Giter Club home page Giter Club logo

Comments (5)

kuitos avatar kuitos commented on May 27, 2024 1

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.

louisscrew avatar louisscrew commented on May 27, 2024

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.

kuitos avatar kuitos commented on May 27, 2024

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.

louisscrew avatar louisscrew commented on May 27, 2024

Thank you very much for your answer.

from mobx-vue.

kuitos avatar kuitos commented on May 27, 2024

Feel free to ask any questions!😀

from mobx-vue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.