子組件讓父組件進行刷新vuex


首先子組件讓父組件進行刷新,子組件讓爺爺組件進行刷新最好用vuex

1.store已經在全局引入了,現將狀態存起來

const updateStore = {
    state: {
      confirm: false
    },
    mutations: {
      setStore: (state, updateStoreData) => {
        state.confirm = updateStoreData
      }
    }
  }
  
  export default updateStore

2 .子組件做完刪除操作后,直接將狀態更改,記得一定要是接口調完哦

  deleteStocking(id) {
      const _this = this
      this.$confirm('刪除此信息', {
        confirmButtonText: '確定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        warehouseApi.stocking.deleteStocking({ id }, res => {
          this.$message.success(res.msg)
          this.$store.commit('setStore', true)
          this.handlePageCurrentChange(1)
        })
      })
    },

3.在computed里面去拿到最新的數據,並且通過調接口刷新后將狀態改回來

  computed: {
      submitStatus () {
        return this.$store.state.updateStore.confirm
      }
    },
   watch: {
      submitStatus (val) {
        if (val) {
          Promise.all([this.getWarehouseDetail(), this.getInventoryDetail()]).then(()=> {
            this.$store.commit('setStore', false)
          })
        }
      }
    },


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM