美文网首页
Vue3按需引入ElementUI

Vue3按需引入ElementUI

作者: 米那斯提力斯 | 来源:发表于2022-05-13 16:49 被阅读0次

    1、npm install --save element-ui --legacy-peer-deps
    2、npm install babel-plugin-component -D --legacy-peer-deps
    3、配置babel.config.js

    module.exports = {
      presets: [
        "@vue/cli-plugin-babel/preset",//这行是默认有的,其余是要加的。
        ["@babel/preset-env", { modules: false }],//之前第一项写的是es2015,但是报错了,后来看了别的博主,发现因为Vue版本太高了,写es2015会出错。
      ],
      plugins: [
        [
          "component",
          {
            libraryName: "element-ui",
            styleLibraryName: "theme-chalk",
          },
        ],
      ],
    };
    

    4、在main.js中引入需要使用的模块

    import { createApp } from 'vue';
    import { Button, Select } from 'element-ui';
    import App from './App.vue';
    import router from './router';
    import store from './store';
    
    const app = createApp(App);
    app.use(Button);
    app.use(Select);
    app.use(store);
    app.use(router);
    app.mount('#app');
    
    

    相关文章

      网友评论

          本文标题:Vue3按需引入ElementUI

          本文链接:https://www.haomeiwen.com/subject/xkkuurtx.html