Vuex: Understanding the usage of Store and vuexstore

Source: Internet
Author: User

Vuex: Understanding the usage of Store and vuexstore

1. What is Store?

As mentioned in the previous article,VuexIs to provide a warehouse,StoreMany objects are stored in the repository. The state is the data source storage location, correspondingVueObjectdata(As mentioned lateractionsAndmutationsCorrespondsmethods).

In useVuexUsuallyStoreInstancenew Vuex.store({state,getters,mutations,actions})Many sub-modules are also used.modules.

Conclusion,StoreClass is the repository for data storage and management methods. The implementation method is to pass data and methods into its instance in the form of objects. Note that only one application or project can exist.StoreInstance !!

2. Store source code analysis

Class Store {constructor (options ={}) {// 1. part 2 'assert (Vue, 'must call Vue. use (Vuex) before creating a store instance. ') // make sure that the Vue exists assert (typeof Promise! = 'Undefined', 'vuex requires a Promise polyfill in this browser. ') // ensure that promise exists // 2. get the state, plugins, and strict const {state ={}, // rootState plugins = [], // plug-in strict = false // whether strict mode} = options // 3. store internal state to create the internal store attribute this. _ options = options // storage parameter this. _ committing = false // identify the submission status. Make sure that the state can be changed only in mutation and not outside. _ actions = Object. create (null) // store user-defined actions this. _ mutations = Object. create (null) // store user-defined mutations this. _ wrappedGetters = Object. create (null) // store user-defined getters this. _ runtimeModules = Object. create (null) // store the runtime modules this. _ subscribers = [] // stores all subscribers with mutation congestion changes this. _ watcherVM = new Vue () // use the Vue instance method and $ watch to observe changes. // 4. direct this of dispatch and commit to the current store instance const store = this const {dispatch, commit} = this. dispatch = function boundDispatch (type, payload) {return dispatch. call (store, type, payload)} this. commit = function boundCommit (type, payload, options) {return commit. call (store, type, payload, options )}}

Next, we will analyze each module step by step.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.