vue——全局引入vant,但是一直在报错Vant is not defined


转载自:https://blog.csdn.net/liyangyang1998/article/details/108360291

    https://www.cnblogs.com/qing0228/p/13915355.html

 

我的情况

  在main.js中全局引入vant和css,启动项目后,控制台一直报错Vant is not defined

 

原因

  项目之前已经通过babel-plugin-component插件,实现了按需导入Vant的组件

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

解决方法

  去除在.babelrc文件或babel.config.js文件 中的配置

  .babelrc

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

  babel.config.js

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM