1.axios的get請求傳參、、、.axios中delete數據請求和get的請求方式是一樣的
// axios.get('http://localhost:3000/axios?id=123').then(function(ret){
// console.log(ret.data)
// })
// axios.get('http://localhost:3000/axios/123').then(function(ret){
// console.log(ret.data)
// })
// axios.get('http://localhost:3000/axios', {
// params: {
// id: 789
// }
// }).then(function(ret){
// console.log(ret.data)
// })
get請求傳參參數可以拼接在地址欄中進行傳遞,同當要傳遞的參數是一個對象的時候,可以使用第三中的傳遞方式,將傳輸對象放在一個對象當中,同時作爲屬性爲params的屬性值進行傳遞
2,axios中post和put請求數據參數的傳遞
// axios.post('http://localhost:3000/axios', {
// uname: 'lisi',
// pwd: 123
// }).then(function(ret){
// console.log(ret.data)
// })
// var params = new URLSearchParams();
// params.append('uname', 'zhangsan');
// params.append('pwd', '111');
// axios.post('http://localhost:3000/axios', params).then(function(ret){
// console.log(ret.data)
// })
// axios put 請求傳參
axios.put('http://localhost:3000/axios/123', {
uname: 'lisi',
pwd: 123
}).then(function(ret){
console.log(ret.data)
})
post和put請求數據參數的傳遞,參數是作爲一個對象進行直接的傳遞
值的注意的是,axios請求是一個異步的請求。在進行請求數據時,通常都會進行一些簡單的基本配置。
在axios和vue進行搭配使用時,這也是vue作者尤雨溪推薦的一種方式,在依賴中進行下載,然後在main.js中進行導入,通常都會將axios掛載到vue的原型上,在使用的時候和es7中async和await進行搭配使用。