Vue - 在没有 VueRouter 的情况下观看 url
Vue - watch url without VueRouter
是否可以在不包含 VueRouter 的情况下对 Vue 组件中的 URL 更改做出反应?
如果 VueRouter 存在,我们可以观察 $route,但是,我的应用程序不依赖 VueRouter。
export default {
watch: { '$route': route => console.log(window.location.href) }
}
在我使用vue router之前,我做了这样的事情......
data: function() {
return {
route: window.location.hash,
page: 'home'
}
},
watch: {
route: function(){
this.page = window.location.hash.split("#/")[1];
}
}
是否可以在不包含 VueRouter 的情况下对 Vue 组件中的 URL 更改做出反应?
如果 VueRouter 存在,我们可以观察 $route,但是,我的应用程序不依赖 VueRouter。
export default {
watch: { '$route': route => console.log(window.location.href) }
}
在我使用vue router之前,我做了这样的事情......
data: function() {
return {
route: window.location.hash,
page: 'home'
}
},
watch: {
route: function(){
this.page = window.location.hash.split("#/")[1];
}
}