1. 程式人生 > WINDOWS開發 >引用thinkcmf的api時more欄位無法正確傳值的問題

引用thinkcmf的api時more欄位無法正確傳值的問題

如使用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)