代码之家  ›  专栏  ›  技术社区  ›  Delcon

Vue原型MyModule并将范围设置为Vue

  •  1
  • Delcon  · 技术社区  · 7 年前

    import api from '@/js/api'
    Vue.prototype.$api = api
    

    在我的api中,我可以通过 this 如果我 default export 函数

    //api.js
    import Vue from 'vue'
    
    export default function () {
       console.log('default export', this)
       //=> Vue
    }
    

    我必须通过调用此函数 Vue.prototype.$api()

    我希望能够导出一个模块,而不丢失

    var MyModule = {
        this.fn1 = function(){console.log(this) //=>Vue}
        this.fn1 = function(){console.log(this) //=>Vue}
    }
    

    1 回复  |  直到 7 年前
        1
  •  0
  •   Delcon    7 年前

    我发现这是不可能的。

    这个 this .then()