Vue-axios使用QS(QueryString)插件,Vue-axios无法发送参数给后端(包含但不限于php)。

推荐方法(最简单):

步骤一:
导入QueryString:

<script src="//cdn.bootcss.com/qs/6.5.2/qs.min.js"></script>

步骤二:
Window.QS就好了

终于搞定了,有没有点儿小激动.
methods:{
            Get_Visit:function () {
                var that = this;
                axios.post('index.php',
                    window.Qs.stringify({
                    method:"visit",
                    }),
                ).then(function (response) {
                     console.log(response);
                        that.visit_time = response.data.visittime;
                        console.log(that.visit_time);
                        }).catch(function (error) {
                        console.log(error);
                             });
            }
        },

在这里插入图片描述
其他方法1(后方附代码):

在这里插入图片描述
下载
axios 自带 qs 可直接引用
npm i qs or yarn add qs
引入
// 在main.js
import axios from ‘axios’;
Vue.prototype. h t t p = a x i o s ; i m p o r t q s f r o m ′ q s ′ V u e . p r o t o t y p e . http = axios; import qs from 'qs' Vue.prototype. http=axios;importqsfromqsVue.prototype.qs = qs;
使用

//在 xx.vue
let params= {
code:“1234”,
name:“yyyy”
};
this. h t t p . p o s t ( ′ u r l ′ , t h i s . http.post('url',this. http.post(url,this.qs.stringify( params)
).then(res=>{
console.log(‘res=>’,res);
})
下载
axios 自带 qs 可直接引用
npm i qs or yarn add qs
引入
// 在main.js
import axios from ‘axios’;
Vue.prototype. h t t p = a x i o s ; i m p o r t q s f r o m ′ q s ′ V u e . p r o t o t y p e . http = axios; import qs from 'qs' Vue.prototype. http=axios;importqsfromqsVue.prototype.qs = qs;
使用

//在 xx.vue
let params= {
code:“1234”,
name:“yyyy”
};
this. h t t p . p o s t ( ′ u r l ′ , t h i s . http.post('url',this. http.post(url,this.qs.stringify( params)
).then(res=>{
console.log(‘res=>’,res);
})

作者:不遭人妒是庸才
链接:https://www.jianshu.com/p/cc9a4bcf2610
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

其他方法2:
在这里插入图片描述
https://blog.csdn.net/WebDestiny/article/details/100558371

猜你喜欢

转载自blog.csdn.net/qq_43228135/article/details/105060393