我正在学习Vuex,但遇到了运行mapState的挑战,我认为mapGetters和mapMutations也会带来同样的挑战。
我在非节点环境中运行xampp localhost中的代码,并且我一直收到错误,如
Uncaught SyntaxError: Unexpected token {
这是我的代码:
的index.html
<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.js
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扩展安装到chrome中但无法启动devtool以使我能够在vue devtool中运行代码。
答案 0 :(得分:1)