首页 > 其他 > 详细

vue await async

时间:2019-10-24 11:16:12      阅读:87      评论:0      收藏:0      [点我收藏+]
1. await, async使用
函数头单独封装出去
views/methods.js页面
import { one } from ‘api/general.js‘;
async function change() {
let data = {},
Obj = {},
key = ‘‘;

data = await one();

for (key in data.data) {
Obj[key] = data.data[key];
}
return Obj;
}

export {
change
}


------------------------------
api/general.js页面
//先执行的函数
function one() {
return fetch({
url: url,
method: ‘get‘,
})
}

export {
one
}


//传参的:
//function one(data) {
   // return fetch({
// url: url,
// method: ‘get‘,
// data: ‘data‘
// })
//}


------------------------
页面调用封装的函数头
import { change } from ‘views/methods.js‘

export default { 
     data() {
changeObj : {}
}
     created() {
change().then(res => {
this.changeObj = res;
});
    }

vue await async

原文:https://www.cnblogs.com/namehou/p/11730694.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!