只是執行了一次push,為何會向數組里push兩條相同的數據呢。百思不得其解。(this.state.updateTripInfoObj.people.data).push(obj); // 這里this.state.travellerInfo.after.temporary.people.data.push(obj);
commit('setTripInfoObj', {
type: 'people',
res: this.state.updateTripInfoObj.people.data,
});
commit('setTravellerInfo', this.state.travellerInfo);setTripInfoObj 只會做賦值操作setTripInfoObj(state, payload) { if (payload.type === 'people') {
state.updateTripInfoObj.people.data = payload.res;
} else {
const { address, people, stroke, take } = payload;
state.updateTripInfoObj = { people: people || [], stroke: stroke || {}, address: address || [], take: take || {},
};
}
},
vuex中使用push給數組增加數據,會增加兩條相同的數據
楊__羊羊
2019-02-26 20:05:44