是否可以在不包含 VueRouter 的情况下对 Vue 组件中的 URL 更改做出反应?
如果存在 VueRouter,我们可以查看 $route,但是,我的应用程序不依赖于 VueRouter。
export default {
watch: { '$route': route => console.log(window.location.href) }
}
Run Code Online (Sandbox Code Playgroud)
在我使用 vue router 之前,我做了这样的事情......
data: function() {
return {
route: window.location.hash,
page: 'home'
}
},
watch: {
route: function(){
this.page = window.location.hash.split("#/")[1];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10276 次 |
| 最近记录: |