【发布时间】:2022-01-12 00:58:03
【问题描述】:
我正在尝试使用 vue js 开始一个新项目。我想我通过终端拥有了我需要的所有依赖项。我安装了 npm、vue、vue-bootstrap 和 vue-router。错误来自 router.js 的第 7 行,Vue.use(VueRouter)。
这是我的 main.js 的代码
import Vue from "vue"
import App from "./App.vue"
import router from "./router.js"
import BootstrapVue from "bootstrap-vue"
import "bootstrap/dist/css/bootstrap.css"
import "bootstrap-vue/dist/bootstrap-vue.css"
Vue.use(BootstrapVue)
Vue.config.productionTip = false
new Vue({
router,
render: h => h(App),
}).$mount('#app')
这是我的 router.js
import Vue from "vue"
import VueRouter from "vue-router"
import Home from "@/pages/Home.vue"
import About from "@/pages/About.vue"
import Contact from "@/pages/Contact.vue"
Vue.use(VueRouter)
export default new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/about',
name: 'about',
component: About
},
{
path: '/contact',
name: 'contact',
component: Contact
}
]
})
对不起,我把 import vue 行和代码指示器放在同一行,它被切断了,我仍然有错误。
完整的错误是这样的:
router.js?41cb:7 Uncaught TypeError: Cannot read properties of undefined (reading 'use')
at eval (router.js?41cb:7)
at Module../src/router.js (app.js:1261)
at __webpack_require__ (app.js:849)
at fn (app.js:151)
at eval (main.js:12)
at Module../src/main.js (app.js:1141)
at __webpack_require__ (app.js:849)
at fn (app.js:151)
at Object.1 (app.js:1274)
at __webpack_require__ (app.js:849)
eval @ router.js?41cb:7
./src/router.js @ app.js:1261
__webpack_require__ @ app.js:849
fn @ app.js:151
eval @ main.js:12
./src/main.js @ app.js:1141
__webpack_require__ @ app.js:849
fn @ app.js:151
1 @ app.js:1274
__webpack_require__ @ app.js:849
checkDeferredModules @ app.js:46
(anonymous) @ app.js:925
(anonymous) @ app.js:928
【问题讨论】:
-
你能分享问题中的完整错误
-
我的猜测是错误实际上来自
main.js- 因为 Vue 没有导入,所以 Vue 没有声明,Vue 是undefined- 因此错误,无法读取.useVue (undefined) -
对不起,我的错误,它在我的代码中但在这里的sn-p中被切断了,我已经在主js上导入了vue
-
你用的是什么版本的 Vue?
-
Using Vue 3.2.24-- BootstrapVue 不支持 Vue 3,因此您必须使用 Vue 2 或使用其他组件库
标签: javascript node.js vue.js