axios取消请求
let btns= document.getElementsByTagName('btn');let cancel = null;btns[0].onclick = function (){if(cancel !== null){cancel();//檢測上一次的請求是否完成,如果未完成則取消請求}axios({method: 'GET',url: 'http://localhost:9000/posts',cancelToken : new axios.CanselToken(function (c){cancel = c;})}).then(response=>{console.log(response);cancel = null;//初始化Cancel})}
axios.get(‘/adata').then(ret=>{// data屬性名稱是固定的,用于獲取后臺響應(yīng)的數(shù)據(jù)console.log(ret.data)})
.query方式傳參和接收參數(shù)
傳參: this.$router.push({path:'/xxx'query:{id:id}})接收參數(shù): this.$route.query.id通過url傳遞參數(shù)
axios.get(‘/adata?id=123').then(ret=>{console.log(ret.data)})query相當(dāng)于get請求,頁面跳轉(zhuǎn)的時候,可以在地址欄看到請求參數(shù),而params相當(dāng)于post請求,參數(shù)不會再地址欄中顯示
傳參是this.$router,接收參數(shù)是this.$route,這里千萬要看清了!!!
總結(jié)
- 上一篇: vue3.x案例 购物车
- 下一篇: JDBC批量操作批量增加批量修改