axios的请求默认数据会自动进行json编码。。。
怎么做才可以避免axios自动编码呢?
使用qs来解决
安装:npm install qs --save
参考:https://blog.csdn.net/baidu_41601048/article/details/82913530
https://blog.csdn.net/kirinlau/article/details/82669013
我们引入这个插件import QS from 'qs'
然后使用
整体代码如下
async requests (that, url, data, type) {
               try {
                   // 允许使用cookie数据
                   that.$axios.defaults.withCredentials = true
                   // 判断请求类型
                   if (type === 'get') {
                       return (await that.$axios.get(url, { params: data })).data
                   } else if (type === 'post') {
                       return (await that.$axios.post(url, QS.stringify(data), { headers: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8' } })).data
                   } else {
                       return null
                   }
               } catch (e) {
                   return null
               }
           }