axios可以通过async和await来实现同步请求。
async是用来修饰方法的,声明该方法为异步请求方法;
await只能在async修饰的方法中使用,它的功能和同步请求的功能是一样,当await修饰一行代码的时候,前端的加载走到这行代码的时候就会变成同步加载,只有等到这行代码执行完成之后才会执行后面的代码。
``
```async get(cyhb) {
await axios
.get("https://api.exchangerate-api.com/v4/latest/" + cyhb)
.then((res) => {
this.getdata = res.data;
})
.catch((err) => {
console.log(err);
});
},
//2.
async cxjs_btn() {
await this.get(this.cyhb_sx);
},