我的vue.js单个文件组件中有以下js函数,我想尝试在axios.post
请求的URL无法访问时捕获异常。我把整个代码放在try块中,但我仍然没有得到我在catch块中的警告
使用.catch更新
deploySelected: function(){
this.showStatus = true ;
// animate open the status window.
$("#status_update").animate({height: '500'})
var url = "http://test-web-machine01.localsite.com:5060/scripts/request_deploy";
axios.post(url)
.then(response => {
if (typeof response.data.reason != "undefined"){
alert("Recieved Status: " + response.data.status + ",\nReason: " + response.data.reason);
}
var req_id = response.data.result.request_id;
this.statusMessage = "Initiating deployment of Scripts for Request ID: " + req_id ;
})
.catch((err) => alert(err))
console.log(url);
}
答案 0 :(得分:0)
我得到了这样的工作:.catch((err) => alert(err))
感谢@Jaromanda