如使用https://demo5.thinkcmf.com/api/portal/articles增加文章时,api文档提示more字段为array,如果不正确设置post导致无法请求
以在VUE中为例:
1、post的Content-Type务必设置成application/x-www-form-urlencoded
2、VUE需要qs的支持,将post的json序列号
npm install qs,在相应页面import qs from ‘qs‘
详细POST代码如下:
this.axios.post(‘xxxx‘, qs.stringify(params), { headers: { ‘Content-Type‘: ‘application/x-www-form-urlencoded; charset=UTF-8‘ } }) .then(res => { console.log(res); }) .catch(function(error) { console.log(error); })
或者使用URLSearchParams()
const params = new URLSearchParams() params.append(‘categories‘, categories) params.append(‘more[photos][photos_urls]‘,url) params.append(‘more[photos][photos_names]‘,name)
引用thinkcmf的api时more字段无法正确传值的问题
原文:https://www.cnblogs.com/chajie/p/12677365.html