async与await的使用
async/await时ES7引入的新语法,async关键字用于函数上(async函数的返回值时Promise实例对象),await关键字用于async函数中(await可以得到异步的结果)
async function queryData() { var res = await new Promise(function(resolve, reject) { setTimeout(function() { resolve('kun&ikun'); }, 1000) }) console.log(res); } queryData();
async/await处理多个异步请求
axios.interceptors.response.use(function(res) { var data = res.data return data; }, function(error) { console.log(error); }); axios.get('http://localhost:3000/adata').then(function(res) { console.log(res); })