參考:https://blog.csdn.net/weixin_43851769/article/details/86505164
qs 是一個增加了一些安全性的查詢字符串解析和序列化字符串的庫。
步驟:
1. 安裝
npm install qs
2. 在需要用到的組件中
import qs from 'qs’
qs.parse()——將URL解析成對象的形式
qs.stringify()——將對象 序列化成URL的形式,以&進行拼接
qs.stringify()使用:
methods: { getData() { let _this = this,
params = { param1: _this.param1,
param2: _this.param2 } }; _this.axios.get('****', qs.stringify(params)).then(function(res) { if (res.status == 200 && res.data.result == 0) { alert('success'); }else{ alert('fail'); } }).catch(function(err) { console.log(err); }) }, }
3. 本人解決方式
個人是沒用qs,采用其他方式傳的:
methods: { getData() { let _this = this, param = { param: { param1: _this.param1,
param2: _this.param2 } }; _this.axios.get('****', { params: param }).then(function(res) { if (res.status == 200 && res.data.result == 0) { alert('success'); }else{
alert('fail');
} }).catch(function(err) { console.log(err); }) }, }