<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Vue-router</title>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<body>
<div id="app">
<router-view></router-view>
</div>
<script>
const foo1 = {
template:`<div>
我是foo1
<button @click="foo2">go foo2</button>
</div>`,
methods:{
foo2(){
this.$router.push('/foo2')
}
}
}
const foo2 = {
template:`<div>
我是foo2
<button @click="foo1">go foo1</button>
</div>`,
methods:{
foo1(){
this.$router.push('/foo1')
}
}
}
const routes = [
{path:'/foo1',component:foo1},
{path:'/foo2',component:foo2},
]
const router = new VueRouter({
routes
})
var vm = new Vue({
el: '#app',
router,
data: {
},
methods: {
},
});
</script>
</body>
</html>