在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vuex通過mounted獲取后臺導航,渲染A組件,然后點擊按鈕跳轉到B組件,在

vuex通過mounted獲取后臺導航,渲染A組件,然后點擊按鈕跳轉到B組件,在B組件中修改導航內容,返回A組件渲染修改后的內容

圖片描述

需求:點擊跳轉B組件,在B組件中增減刪除ABCD,然后點擊B組件的返回按鈕,A組件的nav隨時刷新
說明:這是A組件的獲取數據,渲染頁面

` mounted(){
  this.$store.dispatch('acChannels')
  this.$store.commit('loading', true)
},
computed: {
  channels() {
    console.log(this.$store.state.channels)
    return this.$store.state.channels
  }
},`

這是B組件在修改數據后的代碼:

 methods: {
    backIndex() {
      this.$router.push("/topic");
    },
    deleteChannel(item, index) {
      if(index !== 0) {
        this.$store.commit('increment', index)
        this.addChannel.push(item)
      }
    },
    appendChannel(item, index) {
      this.addChannel.splice(index, 1)
      this.$store.commit('decrement', item)
    }

然后在B組件修改完數據之后,返回A組件,computed總執(zhí)行兩次,第一次輸出的是修改后的數據,然后monted又執(zhí)行了,此時computed也再執(zhí)行一次,有輸出的是從數據庫獲得導航,怎么讓AB組件的數據保持同步或者在B組件數據改變后,A組件實時刷新呢

回答
編輯回答
故林

弄一個全局數組,然后在A頁面獲得這個數組內容,在B頁面改變這個數組,A頁面也會跟著變化

2017年1月18日 03:04