用的是vue2
在项目的main.js里面:
const store = new Vuex.Store({
state: {
isCur:0
},
})
new Vue({
el: '#app',
template: '<App/>',
router,
store,
components: { App }
})
在其中的一个组件中:
<router-link v-for="(value,index) in Anav" v-text="value.text" :to="value.path" :class="{cur:isCur==index}" @click.native="this.$store.state.isCur=index"></router-link>
这里的“this.$store.state.isCur”访问不到,请问是什么原因?
你可以试试官方的mapGetters,一般在项目里没有直接去访问
store
的,都是通过mapGetters
去访问而且如果要像你那样访问的话,应该这样写才对
不需要this