반응형
학습되지 않은 구문 오류 및 Vuex 식별자
저는 Vuex를 배우고 있지만 mapState를 실행하는 데 어려움이 있습니다.mapGetters와 mapMutations도 같은 문제를 일으킬 것으로 예상됩니다.
비노드 환경에서 xampp localhost에서 코드를 실행하고 있는데 다음과 같은 오류가 계속 발생합니다.
Uncaught SyntaxError: Unexpected token {
아래 코드는 다음과 같습니다.
index.displaces를 표시합니다.
<script src="./vue.js"></script>
<!--<script src="./vuex.min.js"></script>-->
<div id="app">
<counter></counter>
<p>
<button @click="increment">+</button>
<button @click="decrement">-</button>
</p>
</div>
<script src="./example.js"></script>
example.displaces 를 참조해 주세요.
import { mapState } from './vuex.min';
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment: state => state.count++,
decrement: state => state.count--
}
})
const Counter = {
template: `<div>{{ count }}</div>`,
/*computed: {
count () {
return this.$store.state.count
}
}*/
computed:mapState({})
/*
I have inserted mapState this way
though the example given is
import { mapState } from 'vuex';
export default {
computed: mapState({
//some codes here
})
}
*/
}
const app = new Vue({
el: '#app',
store,
components: { Counter },
methods: {
increment () {
store.commit('increment')
},
decrement () {
store.commit('decrement')
}
}
})
분명 어딘가에 실수가 있거나 아직 선언하지 않은 것이 도움이 필요한 이유일 것입니다.Vue devtool 확장을 크롬에 설치하려고 여러 방법을 시도했지만 vue devtool에서 코드를 실행할 수 있도록 하기 위해 devtool을 시작하지 못했습니다.
압축된(실가동) 빌드에서는 ES6를 내보낼 수 없습니다.를 사용하여 내보내야 합니다.Vuex.mapState()
여기 작업 예가 있습니다.
https://jsfiddle.net/exckyse3/
언급URL : https://stackoverflow.com/questions/48165090/uncaught-syntax-error-and-identifier-with-vuex
반응형
'programing' 카테고리의 다른 글
Vue.js에서의 디버깅 (0) | 2022.06.28 |
---|---|
Vue Devtool 확장 힌트 사용 안 함 (0) | 2022.06.28 |
-1에서 시작하는 루프는 아무것도 인쇄하지 않습니다. (0) | 2022.06.28 |
C# 퍼포먼스 - IntPtr 및 Marshal 대신 안전하지 않은 포인터 사용 (0) | 2022.06.28 |
Vuetify: carousel을 사용하여 컴포넌트를 표시합니다. (0) | 2022.06.28 |