1. 程式人生 > >vue項目中阻止ajax請求

vue項目中阻止ajax請求

fun opera else n) class catch asc erro use

使用axios

var CancelToken = axios.CancelToken;
var source = CancelToken.source();

axios.get(‘/user/12345‘, {
  cancelToken: source.token
}).catch(function(thrown) {
  if (axios.isCancel(thrown)) {
    console.log(‘Request canceled‘, thrown.message);
  } else {
    // handle error
  }
});

// cancel the request (the message parameter is optional)
source.cancel(‘Operation canceled by the user.‘);

vue項目中阻止ajax請求