provide inject
<!-- father -->
import Store from './store.js'
data() {
const store = new Store(this)
return {
store,
holdLoading: false,
addLoading: false
}
},
provide() {
return {
store: this.store
}
},
mounted() {
this.store.init()
},
<!-- body: -->
inject: ['store'],
store.js
import Vue from 'vue'
import store from '@/store.js'
const _vm = Vue.prototype
const Store = function () {
// 根实例
this.commodityProp = "商品名"
// 页面响应
this.pageLoading = false
this.pageErr = null
}
Store.prototype.operatePriceList = function () {}