vuex清掉数据_如何重置/擦除vuex存储数据?
在我/src/store/文件夹我有actions.js,index.js,mutations.js和state.js它包含以下信息如何重置/擦除vuex存储数据?actions.jsexport default {}index.jsimport Vue from 'vue'import Vuex from 'vuex'import state from './state'import actio
在我/src/store/文件夹我有actions.js,index.js,mutations.js和state.js它包含以下信息如何重置/擦除vuex存储数据?
actions.js
export default {}
index.js
import Vue from 'vue'
import Vuex from 'vuex'
import state from './state'
import actions from './actions'
import mutations from './mutations'
Vue.use(Vuex)
export default new Vuex.Store({
state,
actions,
mutations
})
mutations.js
export default {
TOGGLE_LOADING (state) {
state.callingAPI = !state.callingAPI
},
TOGGLE_SEARCHING (state) {
state.searching = (state.searching === '') ? 'loading' : ''
},
SET_USER (state, user) {
state.user = user
},
SET_TOKEN (state, token) {
state.token = token
}
}
和state.js
export default {
callingAPI: false,
searching: '',
serverURI: 'http://10.110.1.136:8080',
user: null,
token: null,
userInfo: {
messages: [{1: 'test', 2: 'test'}],
notifications: [],
tasks: []
}
}
现在,当用户登录时,我保持状态的
this.$store.commit('SET_USER', response.data)
现在,当用户注销时,我跑我components/logout.vue文件,在其中它有以下代码:
export default {
data() {},
created() {
localStorage.setItem('vuex', null);
this.$store.commit('SET_USER', null);
window.localStorage.clear();
window.sessionStorage.clear();
}
}
但由于某种原因,数据以某种方式持续存在。
2017-09-13
hidar
+0
'但由于某些原因,该数据以某种方式persisted.'持久保存在哪里?在'state.user'或localStorage中? –
+0
它坚持'state.user' –
+0
我不确定最新错误,同样的作品[这里](http://jsfiddle.net/zfab6tzp/22/) –
更多推荐
所有评论(0)