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();
    }
}

 

posted @ 2022-06-30 10:40  haha-uu  阅读(47)  评论(0编辑  收藏  举报