如何在vue的原型上挂载对象方法

需求:想要拦截this.$router里面的方法进行拦截、但是找不到正确的this

const main = {
  install(Vue) {
    // 重写replace 方法
    
    Vue.prototype.$_router = {
      push(){
        // this.$router.push(ars)
        console.log(this)
      }
    }

  },
}

Vue.use(main)
阅读 2.3k
1 个回答

应该是修改route的原型

route.prototype.push=()=>{}

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题