> 文章列表 > try catch的应用

try catch的应用

try catch的应用

用 async /await方法时,遇到一个问题:不加try/catch,在接口报错时,页面没有提示,一直转圈。加上就是走catch-就有错误提示了

async Add() {//点击事件const data = await testApi({id: this.id,});if (data.code == "200") {this.Loading = false;}else{this.Loading = false;return this.$message.error(data.message);}
}
async Add() {//点击事件try{const data= await testApi({id: this.id,});if (data.code == "200") {this.Loading = false;}else{this.Loading = false;return this.$message.error(data.message);}}catch(err){		this.$message.error(err.message);this.Loading = false;}
}

汽车维修技术