首页 > 技术文章 > vue——qs插件的使用

linjiangxian 2019-10-15 16:45 原文

参考:https://blog.csdn.net/weixin_43851769/article/details/86505164

 

qs 是一个增加了一些安全性的查询字符串解析和序列化字符串的库。

 

步骤:

1. 安装

npm install qs

2. 在需要用到的组件中

import qs from 'qs’

 

 

qs.parse()——将URL解析成对象的形式

qs.stringify()——将对象 序列化成URL的形式,以&进行拼接

 

qs.stringify()使用:

methods: {
      getData() {
        let _this = this,            
       params = { param1: _this.param1,
        param2: _this.param2 } }; _this.axios.get(
'****', qs.stringify(params)).then(function(res) { if (res.status == 200 && res.data.result == 0) { alert('success'); }else{         alert('fail');       } }).catch(function(err) { console.log(err); }) }, }

 

3. 本人解决方式

个人是没用qs,采用其他方式传的:

methods: {
      getData() {
        let _this = this,
          param = {
            param: {
              param1: _this.param1,
         param2: _this.param2 } }; _this.axios.get(
'****', { params: param }).then(function(res) { if (res.status == 200 && res.data.result == 0) { alert('success'); }else{
        alert('fail');
      } }).
catch(function(err) { console.log(err); }) }, }

 



推荐阅读