async & await
在某些大型项目中,为了代码可读性强、便于维护,损失部分性能获得方便的维护,这时可以通过async、await可以让异步变为同步操作。
async就是来声明一个异步方法,await是用来等待异步任务执行。
methods: { async search(){ //根据用户输入的搜索条件,基于axios发送异步请求(https://web-server.itheima.net/emps/list)到服务端... let result = await axios.get('https://web-server.itheima.net/emps/list?name=xxx&gender=xxx&job=xxx'); this.employees = result.data.data; }}
注意:await关键字只在async函数内有效,await关键字取代then函数,等待获取到请求成功的结果值 。
浙公网安备 33010602011771号