有人可以为使用Rails应用程序为Vuex设计应用程序结构提供一些建议吗?
我继承了一个应用程序,需要对其进行扩展。无论我做什么,我都无法让Vuex商店与任何Vue组件进行通信。
该应用程序是由以前的开发人员设计的,包括Vue组件而不是Vuex。看起来像这样:
Root.
|
|-- App
|
|-- Front-end
|
|-- components
|
|-- init
|
|-- packs
|
etc.
仅用于故障排除,我在/init/index.js文件中设置VueX,如下所示:
// Vue import
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex)
import { mapState, mapStore, mapActions, mapGetters } from 'vuex';
export default new Vuex.Store({
state: {
count: 0
},
mutations: {
increment (state) {
state.count++
}
}
})
但是我所有的组件都是以这种方式构造的,所以我无法导入商店:
// components/example.js
module.exports = {
data: function() {
return {
}
},
computed: {
count: {
get: function() {
return this.$store.state.count
}
}
}
}
// components/example.vue
<template>
[...]
</template>
<script src="./controller.js"></script>
<style lang="scss" src="./controller.scss"></style>