【问题标题】:Vue - watch url without VueRouterVue - 没有 VueRouter 的观看 url
【发布时间】:2018-06-28 03:35:40
【问题描述】:

是否可以在不包括 VueRouter 的情况下对 Vue 组件中的 URL 更改做出反应?

如果存在 VueRouter,我们可以观察 $route,但是,我的应用程序不依赖 VueRouter。

export default {
    watch: { '$route': route => console.log(window.location.href) }
}

【问题讨论】:

标签: url vue.js watch


【解决方案1】:

在我使用vue路由器之前,我做过这样的事情......

data: function() {
  return {
     route: window.location.hash,
     page: 'home'
  }
},
watch: {
  route: function(){
    this.page = window.location.hash.split("#/")[1];
  }
}

【讨论】:

  • 有一个hashchange 事件。看来海报是在看href
猜你喜欢
  • 1970-01-01
  • 2020-08-25
  • 2020-06-26
  • 2019-11-16
  • 2021-04-03
  • 1970-01-01
  • 1970-01-01
  • 2018-12-24
  • 2021-03-20
相关资源
最近更新 更多