需求:點擊一條消息跳轉相應的頁面且對應相應的大模塊和辦理狀態為選中狀態
問題描述:點擊一條消息后將需要改變的參數拼接到url地址中跳轉到A頁面,當將參數賦值給辦理狀態時頁面辦理狀態不改變
解決:使用watch監聽屬性監聽url變化 && 給url加時間戳(防止緩存url沒有改變watch監聽不到)
消息列表中點擊事件中:
handleRead (item, index) {
let status = item.status let business_code = item.business_code let getTimestamp=new Date().getTime(); //加時間戳防止url沒有改變watch監聽不到 this.$router.push({ path:`/regulation/xzsp?status=${status}&business_code=${business_code}+${getTimestamp}` }) this.$emit('handle-hide') }
A頁面中:
watch:{ $route(to, from) { // watch屬性監聽路由變化 this.activeNameFn() } }, methods:{ activeNameFn(){ if(this.$route.query.status!=undefined){ this.activeName = this.$route.query.status this.business_code = this.$route.query.business_code console.log(this.activeName,'router') } else { this.activeName = 'DJ' console.log(this.activeName,'11') } console.log(this.activeName) }, }