原型链上的代码改为其他导入引用怎么处理呢?

const g_show_tips = {
    install: function(Vue) {
      Vue.prototype.$showTips=function(op={}){
         return    new Promise((resolve, reject)=>{
               let ssm=new show_tips({
                    ...op,
                    $event:function(e){
                        if(e.res){
                            resolve(e);
                        }else{
                            reject(e);
                        }
                     }
                    })
                    ssm.show();
                    Vue.prototype.$hide=function(){
                        ssm.hide();
                    }
            })
        }
    }
};

现在这样子写可以直接this.$showTips使用,我想改为单独的方法,然后在独立脚本导入这个例如
import a from '@/index.js'

使用
a.showTips({})
这样子使用,我改怎么修改呢

阅读 1k
1 个回答

这样就行:

export default {
   showTipes(){},
   install(Vue){
     Vue.prototype.showTipes = this.showTipes
  }
}
推荐问题