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

1,374 阅读1分钟

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

解决方法:

可以先判断下当前快应用中心华为帐号的countryCode(如何获取详见:developer.huawei.com/consumer/cn…:

app.ux代码片段如下:

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:

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

原文链接:developer.huawei.com/consumer/cn…

原作者:Mayism