class Store{
constructor (options = {}) {
// 1.部分2个‘断言函数'判断条件
assert(Vue, `must call Vue.use(Vuex) before creating a store
instance.`) // 在Store实例化之前一定要确保Vue的存在
assert(typeof Promise !== 'undefined', `vuex requires a Promise polyfill in this browser.`)
//确保promise存在
// 2.结构赋值拿到options里面的state,plugins和strict
const {
state = {}, //rootState
plugins = [], // 插件
strict = false //是否严格模式
} = options
// 3.Store internal state创建store内部属性
this._options = options //存储参数
this._committing = false //标识提交状态,保证修改state只能在mutation里面,不能在外部随意修改
this._actions = Object.create(null) //存储用户定义的actions
this._mutations = Object.create(null) //存储用户定义的mutations
this._wrappedGetters = Object.create(null) //存储用户定义的getters
this._runtimeModules = Object.create(null) //存储运行时的modules
this._subscribers = [] //存储所有堵mutation变化的订阅者
this._watcherVM = new Vue() //借用Vue实例的方法,$watch来观测变化
// 4.将dispatch和commit的this指向当前store实例
const store = this
const { dispatch, commit } = this
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)}}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有