vue路由是根据页面url的不同渲染不同的页面(组件)
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./vue.js"></script>
<script src="./vue-router.js"></script>
<style>
ul {
display: flex;
}
li {
list-style-type: none;
padding: 0 20px;
}
</style>
</head>
<body>
<div id="app">
<ul>
<li><router-link to="/home">首页</router-link> </li>
<li><router-link to="/product">蔬菜</router-link></li>
<li><router-link to="/product">蔬菜</router-link></li>
<li><router-link to="/product">蔬菜</router-link></li>
</ul>
<router-view></router-view>
</div>
<script>
let myhome = Vue.component('home', {
template: `<div>首页</div>`
})
let myproduct = Vue.component('product', {
template: `
<div>
商品分类
</div>
`
})
let router = new VueRouter({
routes: [
{
name: 'index',
path: '/home',
component: myhome
},
{
name: 'productCate',
path: '/product',
component: myproduct
}
]
})
var vm = new Vue({
el: '#app',
router,
data: {
}
})
</script>
</body>
</html>