반응형
외부 js 파일에서 저장소로 액세스(nuxtjs)
컴포넌트 외부의 파일에서 스토어에 액세스하려고 합니다.이 문제를 검색했을 때, 사람들이 내 파일에서 스토어를 Import하고 액세스 할 수 있다고 하는데, 이 작업을 실행할 수 없습니다.
저희 가게는 이렇게 지어졌습니다.
const createStore = () => {
return new Vuex.Store({
state: { ... },
getters: { ... },
mutations: { ... },
actions: { ... },
})
}
js파일로 Import를 시도하고 있습니다.
import store from '@/store'
좋은 생각 있어요?
다음과 같이 인스턴스화 시 스토어를 등록하여 가져올 수 있습니다.
외부 파일some-service.js
:
export default class SomeService {
constructor(store) {
this.store = store
}
doStuff() {
this.store.dispatch('someAction')
}
}
언급URL : https://stackoverflow.com/questions/50316251/access-store-from-outside-js-file-in-nuxtjs
반응형
'source' 카테고리의 다른 글
Node.js에서 로컬 IP 주소를 가져옵니다. (0) | 2022.12.04 |
---|---|
를 「Atribute」에 할 수 ?를 「Atribute」에 할 수 ?를 「Atribute」에 할 수 ? (0) | 2022.12.04 |
@IdClass 또는 @EmbeddedId 중 어떤 주석을 사용해야 합니까? (0) | 2022.12.04 |
Vue JS를 사용하여 HTML에서 동일한 태그에 "v-if"와 "v-else"를 사용하는 방법은 무엇입니까? (0) | 2022.12.04 |
여러 열에 걸쳐 고유한 sqlalchemy (0) | 2022.12.04 |