uni-async.js 311 B

12345678910111213141516171819
  1. // 使用proxy转换为异步化的uni方法
  2. const uniAsync = new Proxy({}, {
  3. get(target, name) {
  4. return (obj) => new Promise((resolve, reject) => {
  5. uni[name]({
  6. ...obj,
  7. success: ret => {
  8. resolve(ret)
  9. },
  10. fail: err => {
  11. reject(err)
  12. }
  13. })
  14. })
  15. }
  16. })
  17. export default uniAsync