VueRouter不工作,如何解决?VueRouter不是构造函数

dl5txlt9  于 2023-11-21  发布在  Vue.js
关注(0)|答案(1)|浏览(184)

我是Vue的新手,有一些nodejs后端经验。我遇到了问题,不断得到一个错误:
“Uncaught TypeError:VueRouter is not a constructor”.这是我的代码(app.js):

const routes=[
{ path:'/home', component: home },
{ path:'/zaposlenik', component: zaposlenik },
{path:'/department', component: department }
]


const route = new VueRouter({
routes
})

const app= new Vue({
router
}).$mount('#app')

字符串
我的department.js看起来像:

const department={template: '<h1>Ovo je odsjek</h1>'}


当然,我还有这个:

<nav class="navbar navbar-expand-sm bg-light navbar-dark">
        <ul class="navbar-nav">
            <li class="nav-item m-1">
                <router-link class="btn btn-light btn-outline-primary" to="/home">Home</router-link>
            </li>

            <li class="nav-item m-1">
                <router-link class="btn btn-light btn-outline-primary" to="/department">Odjel</router-link>
            </li>

            <li class="nav-item m-1">
                <router-link class="btn btn-light btn-outline-primary" to="/zaposlenik">Zaposlenik</router-link>
            </li>
        </ul>

    </nav>

    <router-view></router-view>

</div>

<script src="variables.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.26.0/axios.min.js"></script>

<script src="https://unpkg.com/vue@3"></script>
<script src="https://unpkg.com/vue-router@4"></script>
<script src="home.js"></script>
<script src="department.js"></script>
<script src="zaposlenik.js"></script>
<script src="app.js"></script>


你能帮帮我吗?
先谢谢你了,
Vinko

laawzig2

laawzig21#

import { createApp } from 'vue';
import { createRouter, createWebHistory } from 'vue-router'

const routes=[
{ path:'/home', component: home },
{ path:'/zaposlenik', component: zaposlenik },
{path:'/department', component: department }
]

const router = VueRouter.createRouter({
   history: VueRouter.createWebHashHistory(),
   routes
})

createApp({}).use(router).mount('#app')

字符串
这就对了!来自文档:入门

相关问题