我是 Vue 新手。我一直在尝试使用 Vue-Router 设置一个简单的路由。但是我遇到了一个问题,我不知道为什么。
当我转到网址“http://localhost:8080/#/”时,我可以看到“仪表板”消息,但当我转到网址“http://localhost:8080/#/login”时,我看不到“登录”。
谢谢
index.js
import Vue from 'vue'
import Router from 'vue-router'
import Dashboard from '@/components/Dashboard'
import Login from '@/components/Login'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
component: Dashboard
},
{
path: '/login',
Component: Login
}
]
})
登录.vue
<template>
<p>Login</p>
</template>
<script>
export default {}
</script>
App.vue
<template>
<div id="app">
<router-view></router-view>
</div>
</template>
<script>
export default {}
</script>
仪表板.vue
<template>
<p>Dashboard</p>
</template>
<script>
export default {
name: 'Dashboard'
}
</script>
最佳答案
我不是 Vue 专家,但我觉得你应该导航到 localhost:8080/login
而不是 localhost:8080/#/login
您还在 index.js 的第 16 行中将 Component
大写
关于vue.js - Vue路由器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46752827/