반응형
Vuex: 정의되지 않은 속성 '$store'를 읽을 수 없습니다.
vue.js에 스토어가 설정되어 있으며 컴포넌트의 계산된 부분에서 상태 파라미터에 액세스할 수 있습니다.
computed: {
BASE_URL () {
return this.$store.state.BASE_URL;
}
단, 같은 컴포넌트의 방법으로 스토어에 접속하려고 하면 다음과 같이 됩니다.
methods: {
register: function () {
axios.post( this.BASE_URL + "/web/register", {
username: this.username,
password: this.password,
email: this.email
}).then(function(data){
this.$store.commit('saveToken', data.token);
console.log('token is set to:', this.$store.state.token)
});
}
},
콘솔에서 다음 오류가 나타납니다.
미포함(약속)TypeError: 정의되지 않은 속성 '$store'를 읽을 수 없습니다.
나도 해봤어$store
없이.this
같은 에러가 발생합니다.
여기 뭐가 잘못됐나요?어떻게 하면 고칠 수 있죠?
화살표 기능 대신 Javascript 기능을 사용하고 있습니다.이걸 써보면 효과가 있을 거예요.
methods: {
register () {
axios.post( this.BASE_URL + "/web/register", {
username: this.username,
password: this.password,
email: this.email
}).then( (data) => {
this.$store.commit('saveToken', data.token);
console.log('token is set to:', this.$store.state.token)
});
}
언급URL : https://stackoverflow.com/questions/46335667/vuex-cannot-read-property-store-of-undefined
반응형
'programing' 카테고리의 다른 글
Vuejs - 수집되지 않은 유형 오류: 속성을 재정의할 수 없습니다: $router (0) | 2022.09.03 |
---|---|
Vuex 스토어 변경으로 렌더 새로 고침을 트리거하는 방법 (0) | 2022.09.03 |
잭슨 VS지손 (0) | 2022.09.03 |
구조체 배열 끝에 빈 중괄호 '{ }'가 필요한 이유는 무엇입니까? (0) | 2022.09.01 |
vuejs의 Axios에서 계산된 속성을 자동으로 새로 고치는 방법 (0) | 2022.09.01 |