项目场景:
请求的url中参数含有+号,浏览器会把+号转换成空格。导致传参错误问题描述:
不仅是get请求,post请求也会这样。只要参数是以query类型传递的(会拼接在url后面)解决方案:
对参数进行编码,使用encodeURIComponent()
未处理参数时,浏览器中会把+转换成空格 => 变成 【 name: 中性笔 黑色】
//例如:
const name = '中性笔+黑色'
const url = 'baseinfo/product/getItem?'+'name='+ name ;
处理参数 【 name: 中性笔+黑色】
//例如:
const name = '中性笔+黑色'
const url = 'baseinfo/product/getItem?'+'name='+ encodeURIComponent(name);