Vue引入插件Element-ui 样式不生效

import Vue from 'vue'
import App from './App'
import router from './router'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: ''
})

main.js已经引入了ElementUI的样式,也注册了,但页面没有样式

步骤一:执行如下命令,安装babel-plugin-component

npm install babel-plugin-component  --save

步骤二:在vue项目的.babelrc文件中增加如下JSON

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
      }
    }],
    "stage-2"
  ],
  "plugins": ["transform-vue-jsx", "transform-runtime",
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

重新npm run dev,样式就加载出来了

Vue引入插件Element-ui 样式不生效_第1张图片

你可能感兴趣的:(Vue,vue,js)