共计 1027 个字符,预计需要花费 3 分钟才能阅读完成。
开发者能够通过 res.data 获取接口理论返回的后果,通过 res.code 获取失败的返回 code。
以 storage.get() 接口为例,代码如下:
1<script>
import storage from ‘@system.storage’;
const injectRef = Object.getPrototypeOf(global) || global;
// 注入 regeneratorRuntime
injectRef.regeneratorRuntime = require(‘@babel/runtime/regenerator’);
module.exports = {
onDestroy: function () {console.info("onDestroy");
},
getValue: async fuwww.diuxie.comnction () {
try {
let re = await storage.get({key: 'name'});
console.info("getValue re="+JSON.stringify(re));
let value=re.data;
} catch (error) {console.info("getValue error="+error);
<script>
import storage from ‘@system.storage’;
const injectRef = Object.getPrototypeOf(global) || global;
// 注入 regeneratorRuntime
injectRef.regeneratorRuntime = require(‘@babel/runtime/regenerator’);
module.exports = {
onDestroy: function () {console.info("onDestroy");
},
getValue: async fuwww.diuxie.comnction () {
try {
let re = await storage.get({key: 'name'});
console.info("getValue re="+JSON.stringify(re));
let value=re.data;
} catch (error) {console.info("getValue error="+error);
}
}
}
</script>
这样就会失去手游的相干数据,输入如下:
1
getValue re={“data”:”hanmeimei”}
正文完
发表至: typescript
2021-06-24