vue provide inject 方法
上级组件:
provide() { return { changeSelectOptions: this.changeSelectOptions, switchTabs: () => this.switchTabs, setLoading: this.setLoading, getFilterData: this.getFilterData, getDisplayAreaH: this.getDisplayAreaH }; }, methods: { changeSelectOptions(obj) { // 你的逻辑 }, getDisplayAreaH() { // 你的逻辑 } }
下级组件:
inject: [ 'changeSelectOptions', 'switchTabs', 'setLoading', 'getFilterData', 'getDisplayAreaH' ], methods: { this.changeSelectOptions(value); foldSwitch() { this.fold = !this.fold; if (this.fold) { this.dynamicStyle = { height: '34px', overflow: 'hidden' }; } else { this.dynamicStyle = {} } this.getDisplayAreaH(); } }
记录自己的采坑之路,需要时方便查找