如何storage接口同步调用?
开发者可以通过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 = {
图片来源:www.diuxie.com 手游
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"}