vue3项目中引用vant ui后报如下错误,怎么解决
在项目中的引用
import vant from 'vant';
import 'vant/lib/index.css';
import App from './App.vue'
const app = createApp(App)
app.use(vant);
app.mount('#app')
所出现的错误
index.mjs?7f9c:194 Uncaught TypeError: Cannot read properties of undefined (reading 'install')
at eval (index.mjs?7f9c:194)
at Array.forEach (<anonymous>)
at Object.install (index.mjs?7f9c:193)
at Object.use (runtime-core.esm-bundler.js?5c40:4399)
at eval (main.js?56d7:27)
at Object../src/main.js (app.js:1079)
at __webpack_require__ (app.js:849)
at fn (app.js:151)
at Object.1 (app.js:1188)
at __webpack_require__ (app.js:849)
你需要在vue3项目中正确引用vant ui。请按照以下步骤进行操作:
npm install vant -S
import { createApp } from 'vue'
import App from './App.vue'
import Vant from 'vant'
import 'vant/lib/index.css'
const app = createApp(App)
app.use(Vant)
app.mount('#app')
npm install sass sass-loader -D
module.exports = {
css: {
loaderOptions: {
sass: {
prependData: `@import "@/assets/scss/variables.scss";`
}
}
}
}
<template>
<van-button type="primary">按钮</van-button>
</template>
如果还有问题,请提供更多的详细信息。
已解决,vue3中可能是要vant版本为3点几版本的才可以吧,把vant ui从最新的4点几版本降为3.6.11就可以了