不知道为什么没效果
来源:2-22 状态管理vuex
_追随
2020-05-12 01:06:43
//main.js
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/'
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})
//demo14/index.vue
<template>
<div>
<div>状态管理VUEx</div>
<div>----------------------------</div>
<div>{{msg}}</div>
<button @click="change">按钮</button>
</div>
</template>>
<script>
export default {
data(){
return{
msg:'684',
}
},
methods:{
change(){
this.msg=this.$store.state.count
}
}
}
</script>
//store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
count: 0,
num: 1
},
mutations: {
increment(state, num) {
state.count++
state.num = num;
}
},
actions: {
inc({ commit }, obj) {
commit('increment', obj)
}
}
}
)
3回答
好帮手慕慕子
2020-05-12
同学你好,因为没有注册store,所以不能实现效果。建议修改:

如果我的回答帮助到了你,欢迎采纳,祝学习愉快~
_追随
提问者
2020-05-12
这是目录
_追随
提问者
2020-05-12
然后有行代码没高亮
相似问题
回答 2
回答 1