毕业设计开发记录
前端
后端
1.codeIngniter 接受数据格式问题
CI框架默认接受的数据格式为 Form-data 类型,而 vue-axios 默认格式是 json 类型,这会导致当使用 post 发送数据时,后端接受不到数据
解决方法:配置axios
import axios from 'axios'
//PHP默认接受的参数是form-data类型,而axios默认发送的是json类型
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.transformRequest = [function (data) {
let ret = ''
for (let it in data) {
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
}
return ret
}]
Vue.prototype.axios = axios;