Comments (5)
mobx-vue do not restrict you how to define your store with singleton or multiton, as well as mobx. You could treat any singleton store as global state and import it anywhere.
// xx/store.js
class Store {}
export default new Store()
// App.vue
import store from './xx/store'
class App extends Vue {
store = store;
}
from mobx-vue.
ok,我一般比较喜欢单例模式,我在使用vuex和vuet的时候,在创建vue实例的时候就可以传递一个参数,比如store或者其他。之后在其下所有的子组件都可以通过this.$store或者this.$vm.$store的形式就能获取到store。那么对于mobx-vue来讲,是不是子组件也需要如下进行获取store呢?
// xx/store.js
class Store {}
export default new Store()
// App.vue
import store from './xx/store'
import SubComponent from "./SubComponent.vue"
'component-a': ComponentA
@Component({
subComponent:SubComponent
})
class App extends Vue {
store = store;
}
//SubComponent.vue
import store from './xx/store'
class SubComponent extends Vue {
store = store;
}
上面的SubComponent需要引用一次store是吗?
from mobx-vue.
yep, just import it.
btw, single store is not recommended in mobx paradigm, although not restricted as well. All are up to you.
from mobx-vue.
Thank you very much for your answer.
from mobx-vue.
Feel free to ask any questions!😀
from mobx-vue.
Related Issues (20)
- Lost all of types in <vue-template> when component options wrapped by observer
- Please publish a new version to include some fixes. HOT 1
- mobx cause [Vue warn]: Unknown custom element: <router-link>
- I got error when I use @Observer before @Component with Nuxtjs HOT 4
- mobx-vue does not forward static properties when using vue-class-component HOT 1
- Add Documentation re Optimizing Rendering
- No re-renders when observed state is used in some parts of the template HOT 4
- What's the counterpart of `Vue.nextTick` for mobx-vue?
- Can I use mobx-vue without decorated class properties?
- `observer.js` missing from current dist/package HOT 2
- Module Browser Build
- Vue 3 Compatibility HOT 6
- Exception when using with mobx-state-tree HOT 5
- mobx6 HOT 3
- TypeError: reaction.getDisposer is not a function HOT 6
- [RFC] mobx-vue v3 HOT 18
- mobx-vue是支持vue3.0的吗? HOT 2
- Mobx6 not working HOT 8
- Mobx 6 got `Exception: TypeError: Cannot read properties of undefined` on COLLECTION HOT 3
- Is there a way to add mobx to vue plugin component inside Vue.component, Vue.extend install function? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mobx-vue.