반응형
vuex에 여러 플러그인을 등록하는 방법?
나는 이미 내 프로젝트에서 vue-persistedstate 플러그인을 사용하고 있었다.이제 나는 vuex-pathify 플러그인도 필요하다.
영구 상태의 경우 설정을 포함한 상수를 준비한다.
const persistedStates = [
createPersistedState({
key: process.env.PERSISTENT_COOKIE_NAME,
paths: [
'auth'
],
storage: {
getItem: key => JSON.stringify(cookies.get(key)),
setItem: (key, value) => cookies.set(key, value, { path: '/', expires: '6h', secure: false }),
removeItem: key => cookies.remove(key)
},
}),
createPersistedState({
key: process.env.PERSISTENT_COOKIE_NAME,
paths: [
'user',
],
})
];
그런 다음 다음과 같이 사용하십시오.
const Store = new Vuex.Store({
...
plugin: persistedStates;
...
})
이제 pathify 플러그인도 추가해야겠어.나는 노력했다.
plugin: [persistedStates, pathify.plugin]
그러나 작동하지 않고 오류를 반환함(vuex.esm.js?94e4:368 Uncaught (in promise) TypeError: plugin is not a function
내가 뭘 놓쳤지?
Vuex doc은 매우 직설적이다: https://vuex.vuejs.org/guide/plugins.html
const myPlugin = store => {
// called when the store is initialized
store.subscribe((mutation, state) => {
// called after every mutation.
// The mutation comes in the format of `{ type, payload }`.
})
}
const store = new Vuex.Store({
// ...
plugins: [myPlugin]
})
참조URL: https://stackoverflow.com/questions/63437078/how-to-register-multiple-plugins-in-vuex
반응형
'programing' 카테고리의 다른 글
Vue.js $emit와 $dispatch의 차이점은 무엇인가? (0) | 2022.05.24 |
---|---|
공리가 있는 진행 막대 (0) | 2022.05.24 |
Mac OSX에서 버전 전환을 허용하는 Java 설치 방법 (0) | 2022.05.24 |
Vue.js: 하위 요소에 CSS 클래스 사용 (0) | 2022.05.24 |
이 방법 서명의 줄임표(...)는 무엇인가? (0) | 2022.05.23 |