失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > ts watch路由 参数变化_vue watch 监听路由变化

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

时间:2022-11-17 00:46: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 监听路由变化》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。