ts watch路由 参数变化_vue watch 监听路由变化
首頁(yè)
列表頁(yè)
購(gòu)物車(chē)
會(huì)員中心
import store from "../../store"
import { mapState, mapActions } from "vuex"
export default{
// vue使用props動(dòng)態(tài)傳值給子組件里面的函數(shù)用
props:['floorTitle'],
data(){
return{
active: 0
}
},
created(){
this.changeTabActive()
},
watch:{? // 當(dāng)數(shù)據(jù)發(fā)生改變的時(shí)候再賦值
// floorData 監(jiān)視的對(duì)象
},
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跳轉(zhuǎn),因?yàn)槁窂接袝r(shí)候會(huì)改變,這樣就需要改編程式導(dǎo)航,比較麻煩
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'
}
}
總結(jié)
以上是生活随笔為你收集整理的ts watch路由 参数变化_vue watch 监听路由变化的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 瑞士桁架机器人_机器人库晚报:人工智能可
- 下一篇: data中的数据如何在innerhtml