Vue-router
<router-link to="/"
<router-view
var router = new VueRouter
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue-router</title>
</head>
<body>
<div id="app">
<div>
<router-link to="/">首页</router-link>
<router-link to="/about">关于我们</router-link>
</div>
<div>
<router-view></router-view>
</div>
</div>
<script src="https://cdn.bootcss.com/vue/2.6.11/vue.js"></script>
<script src="https://cdn.bootcss.com/vue-router/2.7.0/vue-router.js"></script>
<script src="index.js"></script>
</body>
</html>
JS
var routes = [{
path: '/',
component: {
template: '<div><h1>首页</h1></div>'
},
},
{
path: '/about',
component: {
template: '<div><h1>关于我们</h1></div>'
}
},
]
var router = new VueRouter({
routes: routes
})
new Vue({
el: '#app',
router: router
})