我有很多参数要保存在param
变量中,然后将其添加到url
中。
如何将参数filter% 5Binprogress% 5D = true
保存在变量param
中?
expand
-> expand: track
在标签网络中返回-> "https://spotify?expand=track&filter%255Binprogress%255D=true"
应为-> "https://spotify?expand=track&filter%5Binprogress%5D=true"
%255D ---> should be %5D
const param = {
expand: track,
'filter%5Binprogress%5D': true //problem here
}
axios({
url: "https://spotify?expand=track&filter%5Binprogress%5D=true",
method: "GET",
headers: {
'Authorization': .....
},
param: param
})
答案 0 :(得分:0)
这是因为对象属性中有特殊字符。
尝试使用引号(单引号或双引号)
const param = {
expand: track,
"filter%5Binprogress%5D": true
}
axios({
url: "https://spotify?expand=track&filter%5Binprogress%5D=true",
method: "GET",
headers: {
'Authorization': .....
},
param: param
})
答案 1 :(得分:-2)
使用引号或括号表示。
const param = {
expand: track
}
param['filter%5Binprogress%5D'] = true;
或使用引号:
const param = {
expand: track,
"filter%5Binprogress%5D": true
}