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.http=axios;importqsfromqsVue.prototype.http = axios; import qs from 'qs' Vue.prototype.qs = qs;
使用

//在 xx.vue
let params= {
code:“1234”,
name:“yyyy”
};
this.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.http=axios;importqsfromqsVue.prototype.http = axios; import qs from 'qs' Vue.prototype.qs = qs;
使用

//在 xx.vue
let params= {
code:“1234”,
name:“yyyy”
};
this.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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章