问题分析对于await的方式调用需要开发者引入@babel/runtime/regenerator,示例代码如下: <script>
const injectRef = Object.getPrototypeOf(global) || global;
// injection regeneratorRuntime
injectRef.regeneratorRuntime = require('@babel/runtime/regenerator');
module.exports = {
}
</script> 解决方法在app.ux文件中起始位置加入上述代码声明即可,具体代码如下: <script> import push from "@service.push"; import device from '@system.device'; const injectRef = Object.getPrototypeOf(global) || global; injectRef.regeneratorRuntime = require('@babel/runtime/regenerator'); module.exports = { data: { hasSaved: "no" }, onCreate() { console.info("Application onCreate"); console.info("push服务提供商:" + push.getProvider()); this.hasSaved = "yes"; push.subscribe({ success: function (data) { console.log("push.subscribe succeeded, regid=" + JSON.stringify(data)); }, fail: function (data, code) { console.log("push.subscribe failed, result data=" + JSON.stringify(data) + ", code=" + code); }, complete: function () { console.log("push.subscribe completed"); } }); this.testAsync(); }, async testAsync() { try { let res = await device.getDeviceId(); console.info("get device id " + JSON.stringify(res.data)); } catch (e) { console.log("get device id error " + e.code); } }, onShow(options) { }, onDestroy() { console.info("Application onDestroy"); }, dataApp: { localeData: {} } }; </script>
|