原因:若配置按需加载后就不允许再配置全局引入组件,同时做以上操作就会导致冲突,出现 Uncaught ReferenceError: Vant is not defined 错误。

main.js包含代码为:

import Vue from 'vue';
import Vant from 'vant';
import 'vant/lib/index.css';

Vue.use(Vant);

与此同时,.babelrc 或babel.config.js 的plugins具有相关按需引入的配置。

解决方法:

  方法1

去除在.babelrc 中添加的配置,

{
  "plugins": [
    ["import", {
      "libraryName": "vant",
      "libraryDirectory": "es",
      "style": true
    }]
  ]
}

或在 babel.config.js 中配置

 

module.exports = {
  plugins: [
    ['import', {
      libraryName: 'vant',
      libraryDirectory: 'es',
      style: true
    }, 'vant']
  ]
};

  方法2

去除main.js中的全局引用,使用按需引用。

  

相关文章:

  • 2022-12-23
  • 2022-02-21
  • 2021-06-26
  • 2021-09-23
  • 2021-05-14
  • 2022-12-23
  • 2021-04-21
  • 2021-06-30
猜你喜欢
  • 2022-12-23
  • 2021-03-26
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案