每当我在vuex中发送操作时,它都会删除我原来的用户状态并将调度操作添加到播放列表。我不知道什么是问题所以分享截图你可能在图像中理解我想说的。
事情是应用程序启动时它使用默认值工作正常但是当我添加一些按钮或事件的调度时,它会从vuex中删除用户状态对象,但保留播放列表中的新项目。我知道当调度播放列表刷新vuex对象时如何保持用户对象同时?
这是我添加的动作并且工作正常,但每次添加内容时我都必须执行此操作,或者如果其他动作则我必须应用相同的操作。
任何想法我都不必每次都要发送用户?
addSongToList() {
playlist.dispatch('addSong', { title: "Beside Me",
mp3: "http://dl.jatt.link/lq.jatt.link/cdn8/1a40cff114c5ee39b75dd3813c3f29dd/cdlzv/Ni%20Mainu-(Mr-Jatt.com).mp3",
});
store.dispatch('updateUser', this.getUser );
}
由于
这是我的playlist.js商店文件:
import Vuex from 'vuex'
let state = {
playerList: []
};
let getters = {
getPlaylist: state => {
return state.playerList
}
};
let actions = {
addSong: ({commit}, song) => {
commit('ADD_SONG_TO_PLAYLIST', song)
}
};
let mutations = {
ADD_SONG_TO_PLAYLIST(state, song) {
state.playerList.push(song)
}
};
let playlist = new Vuex.Store({
state,
getters,
mutations,
actions,
});
global.playlist = playlist;
export default playlist
这是user.js
import Vuex from 'vuex'
import playlist from './playlist'
let state = {
user: {}
};
let getters = {
getUser: state => {
return state.user
}
};
let actions = {
updateUser: ({commit}, user) => {
commit('ADD_USER', user)
},
deleteUser: ({commit}) => {
commit('DELETE_USER')
}
};
let mutations = {
ADD_USER(state, user) {
state.user = user
},
DELETE_USER(state) {
state.user = null
}
};
export default new Vuex.Store({
state,
getters,
actions,
modules: {
playlist
},
mutations,
})