教你使用一套代码解决出海问题

快应用海外不支持一些接口,好比 service.share ,怎么在代码里判断并屏蔽,又不影响国内版本的使用呢?api

解决方法:app

能够先判断下当前快应用中心华为账号的countryCode(如何获取详见:https://developer.huawei.com/...ui

app.ux代码片断以下:this

data: {
      localeObject: ''
    },
    test() {
      device.getServiceCountryCode({
        success: function (ret) {
          this.localeObject = ret.serviceCountryCode
          console.log(ret.serviceCountryCode);
        },
        fail: function (erromsg, errocode) {
          this.localeObject = 'errocode:' + errocode + ',erromsg:' + erromsg
          console.log(erromsg, errocode);
        },
        complete: function () {
        }
      })
      return this.localeObject
    }

页面ux中调用service.share:code

fastAppShare() {
      if (this.$app.$def.test()==='CN') {
        share.share({
          //此处为三方分享内容
        })
      }
    }

原文连接:https://developer.huawei.com/...
原做者:Mayism接口

相关文章
相关标签/搜索