반응형
vuex 스토어 데이터를 리셋/삭제하려면 어떻게 해야 합니까?
인마이/src/store/가지고 있는 폴더actions.js,index.js,mutations.js그리고.state.js다음 정보가 포함되어 있습니다.
actions.syslog
export default {}
index.displaces를 표시합니다.
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
})
돌연변이.복제
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
}
}
및 스테이트를 지정합니다.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();
}
}
하지만 어떤 이유에서인지, 그 데이터는 계속 유지되고 있습니다.
로그아웃으로 스토어를 Import하려고 시도한 적이 있습니까?vue 컴포넌트?
const store = require('path/to/index.js');
그 후, 당신이 작성한 방법으로
store.default.commit('SET_USER', null);
언급URL : https://stackoverflow.com/questions/46201518/how-can-i-reset-erase-a-vuex-store-data
반응형
'programing' 카테고리의 다른 글
| 왜 scanf를 사용하여 문자열 버퍼를 읽으면 앰퍼샌드(&)가 있는 경우와 없는 경우 모두 동작합니까? (0) | 2022.08.28 |
|---|---|
| IntelliJ IDEA에서 Eclipse의 Ctrl+O(개요 표시) 단축키는 무엇입니까? (0) | 2022.08.28 |
| Vue 2의 컴포넌트 어레이에서 아이템을 추가 및 삭제하는 방법 (0) | 2022.08.27 |
| Vuex가 기존 양식 데이터를 상태별로 로드하여 편집 (0) | 2022.08.27 |
| Vuejs 프로젝트 빌드가 서버에서 작동하지 않음 (0) | 2022.08.27 |