一路由import Vue from ‘vue’
import Router from ‘vue-router’
import HelloWorld from ‘@/components/HelloWorld’
import Login from ‘@/components/Login’
import GoodsList from ‘@/views/GoodsList’
import Title from ‘./…/views/Title’
import Image from ‘@/views/Image’
Vue.use(Router)
export default new Router({
routes: [
/{
path: ‘/’,
name: ‘HelloWorld’,
component: HelloWorld
},
{
path: ‘/Login’,
name: ‘Login’,
component: Login
},/
{
path: ‘/goodsList’,
name: ‘GoodsList’,
component: GoodsList,
children:[
{
path: ‘title’,
name: ‘title’,
component: Title
},{
path: ‘image’,
name: ‘image’,
component: Image
}
]
}
]
})
二.
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<h2>goodslist</h2>
<router-link to="/goodsList/title">显示商品标题</router-link>
<router-link to="/goodsList/image">显示图片</router-link>
<div>
<router-view></router-view>
</div>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>