vue路由实例
Posted shirliey
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue路由实例相关的知识,希望对你有一定的参考价值。
router.js:
import Vue from ‘vue‘
import Router from ‘vue-router‘
import Home from ‘@/components/Home‘
import HelloWorld from ‘@/components/HelloWorld‘
Vue.use(Router)
export default new Router({
routes: [
{
path: ‘/Home‘,
component: Home
},
{
path: ‘/HelloWorld‘,
component: HelloWorld
},
{
path: ‘/‘,
redirect: ‘/Home‘
}
]
})
Home.vue:
<template>
<div class="home">
<h1>{{ msg }}</h1>
<router-link to="/">Home</router-link>
<router-link to="/HelloWorld">HelloWorld</router-link>
</div>
</template>
<script>
export default {
name: ‘Home‘,
data () {
return {
msg: ‘Home‘
}
}
}
</script>
<style></style>
HelloWorld.vue:
<template>
<div class="HelloWorld">
<h1>{{ msg }}</h1>
<router-link to="/">Home</router-link>
<router-link to="/HelloWorld">HelloWorld</router-link>
</div>
</template>
<script>
export default {
name: ‘HelloWorld‘,
data () {
return {
msg: ‘HelloWorld‘
}
}
}
</script>
<style></style>
以上是关于vue路由实例的主要内容,如果未能解决你的问题,请参考以下文章