欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 前端技术 > vue >内容正文

vue

ts watch路由 参数变化_vue watch 监听路由变化

发布时间:2024/4/13 vue 42 豆豆
生活随笔 收集整理的这篇文章主要介绍了 ts watch路由 参数变化_vue watch 监听路由变化 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

首页

列表页

购物车

会员中心

import store from "../../store"

import { mapState, mapActions } from "vuex"

export default{

// vue使用props动态传值给子组件里面的函数用

props:['floorTitle'],

data(){

return{

active: 0

}

},

created(){

this.changeTabActive()

},

watch:{  // 当数据发生改变的时候再赋值

// floorData 监视的对象

},

computed: {

...mapState({

items: state => store.state.shopcart.items,

totalNumber: state => store.state.shopcart.totalNumber,

totalMoney: state => store.state.shopcart.totalMoney,

itemCount: state => store.state.shopcart.itemCount

})

},

updated(){

this.changeTabActive()

},

methods:{

changeTabbar(active){

console.log(active)

switch (active) {

case 0:

//使用name跳转,因为路径有时候会改变,这样就需要改编程式导航,比较麻烦

this.$router.push({name:'Main'})

break;

case 1:

this.$router.push({name:'goodsList'})

break

case 2:

this.$router.push({name:'cart'})

break

case 3:

this.$router.push({name:'user'})

default:

break;

}

},

changeTabActive(){

this.nowPath=this.$route.path  //vue提供的方法

if(this.nowPath=="/shoppingMall"){

this.active=0

}else if(this.nowPath=="/goodsList"){

this.active=1

}else if(this.nowPath=="/cart"){

this.active=2

}else if(this.nowPath=="/user"){

this.active=3

}

}

},

watch:{

'$route': 'changeTabActive'

}

}

总结

以上是生活随笔为你收集整理的ts watch路由 参数变化_vue watch 监听路由变化的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。