在我的main.js
中,我有router
:
import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import HelloWorld from './components/HelloWorld.vue'
import Home from './components/Home.vue'
Vue.use(VueRouter)
// config the router
const router = new VueRouter({
routers: [
{path: '/home', component: Home},
{path: '/helloworld', component: HelloWorld},
],
mode: "history"
})
new Vue({
router,
el: '#app',
render: h => h(App),
})
我的App.vue
代码:
<template>
<div id="app">
<router-view></router-view>
</div>
</template>
<script>
export default {
data: function() {
return {
helth: 100,
ended: false
}
},
}
</script>
<style scoped>
</style>
HelloWorld.vue
:
<template>
<div>
Home
</div>
</template>
<script>
export default{
data(){
return {msg: 'hello vue'}
},
components: {}
}
</script>
<style scoped>
</style>
HelloWorld.vue
:
<template>
<div>
Hello World
</div>
</template>
<script>
export default{
data(){
return {msg: 'hello vue'}
},
components: {}
}
</script>
<style scoped>
</style>
但在我的浏览器中,无论是x/home
还是x/helloworld
都没有显示任何内容:
修改
我尝试访问此链接:
http://0.0.0.0:8081/Home.vue
但是我的页面出现了以下错误:
无法获取/Home.vue
答案 0 :(得分:0)
将routers
更改为routes
const router = new VueRouter({
routes: [ // <<< here
{path: '/home', component: Home},
{path: '/helloworld', component: HelloWorld},
],
mode: "history"
})
答案 1 :(得分:-1)