10

I don't want to use Vue-Material nor Vuetify.

I want to use Materialize. What I do is:

npm install materialize-css@next

In main.js, where my new Vue App is defined I import Materialize like this:

import 'materialize-css'

Somehow the javascript is working, but the CSS is not loading; I test it with a Card Reveal.

The swapping animation works, but it is not styled. Card Reveal is one of the reasons why I want to use MaterializeCss, those other two don't provide this functionality. And I also want to use 'normal' HTML elements instead of using 100 of new elements (for example in vuetify).

Suisse
  • 3,467
  • 5
  • 36
  • 59

3 Answers3

22

Step 1: installation

npm install materialize-css@next --save
npm install material-design-icons --save

Step 2: import materialize css in src/main.js

At src/main.js

import 'materialize-css/dist/css/materialize.min.css'
import 'material-design-icons/iconfont/material-icons.css'

Step 3: initialize materialize components

Add following code in your component(say App.vue):

import M from 'materialize-css'

export default {
...
mounted () {
    M.AutoInit()
},
...
SheiUn
  • 9
  • 1
  • 4
bruinspaw
  • 621
  • 6
  • 4
9

This line imports the javascript (the entry point of the npm module from node_modules folder):

import 'materialize-css'

To import the CSS files just do this:

import 'materialize-css/dist/css/materialize.css'
Suisse
  • 3,467
  • 5
  • 36
  • 59
  • 3
    I found I needed to add `` in the `index.html` in order for the icons to load. eg. hamburger icon for mobile nav. – David North Mar 04 '19 at 18:29
2

I would also recommend you add the materialize css CDN in the index.html. Aand also create a script tag and add this:

document.addEventListener('DOMContentLoaded', function() {
    M.AutoInit();
 });
Thomas Guillerme
  • 1,747
  • 4
  • 16
  • 23
wisdom
  • 230
  • 2
  • 10
  • Not sure how vue and materializecss share the DOM. I recommend running function once the component is mounted: `mounted: function() { M.AutoInit() }` – user8555937 Nov 19 '19 at 14:27