Vue父子组件通信,路由跳转的实现

219 阅读1分钟

第一步:父组件传递url参数

<tab-bar path="/home"><tab-bar>

第二步:子组件通过props接收传递的url参数

props: {
  path: String
}

第三步:子组件添加click点击事件

<div @click="itemClick"> </div>

第四步:点击事件绑定this.$router.replace(this.path)实现路由跳转

methods: {
   itemClick() {
     this.$router.replace(this.path)
   }
}