vue2项目引入vant2报错Uncaught ReferenceError: vant is not defined

vue2项目引入vant2报错Uncaught ReferenceError: vant is not defined
首先安装vant官网使用流程, 安装 Vant 2:
执行命令npm i vant@latest-v2 -S
然后再main.js文件中导入组件

img


运行项目发现项目报错,截图如下:

img

看了网上关于这个报错的处理,说是要修改.babelrc 或babel.config.js 的plugins 把按需引入的配置注释掉,但是我项目中没有设置按需引入配置:

img


现在不太清楚是什么问题导致的了,这是我的vue和vant版本号:

img

你好,应该是模块没安装的问题

  • 这篇博客: 基于vue 旅游网移动开发中的 使用框架vant babel.config.js配置 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • module.exports = {
      presets: [
        '@vue/cli-plugin-babel/preset'
      ],
      plugins: [
        ['import', {
          libraryName: 'vant',
          libraryDirectory: 'es',
          style: true
        }, 'vant']
      ]
    }