代碼:
<router-link to="/home" @click.native="flushCom">首頁</router-link>
export default {
...
...
methods:{
flushCom:function(){
//router是路由實例,例如:var router = new Router({})
//router.go(n)是路由的一個方法,意思是在history記錄中前進或者後退多少步,0就表示還是當前,類似window.history.go(n)
this.$router.go(0);
}
}
}
@click.native:事件後面要添加.native,不然添加的事件不起作用,具體原因應該是router-link爲了阻止a標籤的默認跳轉事件