操作方法
页面结构
<body>
<div id="app">
<h1>操作方法</h1>
<router-view></router-view>
<br />
<button @click="demo1">按钮跳转首页</button>
<button @click="demo2">按钮跳转会员中心</button>
<button @click="demo3">刷新界面</button>
</div>
</body>
<script src="./vue.min.js"></script>
<script src="./vue-router.js"></script>
逻辑结构
const Home = {
template: `<h1>首页</h1>`
}
const User = {
template: `<h1>会员中心</h1>`
}
const router = new VueRouter({
routes: [
{
path: '/',
component: Home,
},
{
path: '/user',
component: User,
},
]
})
var app = new Vue({
el:'#app',
router,
methods:{
demo1()
{
this.$router.push('/')
},
demo2()
{
this.$router.push({path: '/user', query:{keyword:'参数值'}})
},
demo3()
{
this.$router.go(0)
}
}
})