首先子組件讓父組件進行刷新,子組件讓爺爺組件進行刷新最好用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)
})
}
}
},