在vue中使用query-string处理url的参数


vue中使用query-string,主要是用来处理url中的参数问题。

安装

npm install query-string -s

使用

在 main.js 中:

import querystring from "query-string";
Vue.prototype.$querystring
= querystring;

 

这样就可以在 *.vue 的文件中通过 this.$querystring 使用了。

示例

this.$querystring.parse('?foo=bar');           //{foo: 'bar'}
this.$querystring.parse('#token=bada55cafe');  //{token: 'bada55cafe'}
 let param={ foo:"unicorn", ilike:"pizza" } this.$querystring.stringify(param);  //'foo=unicorn&ilike=pizza'

更多用法,可参考npm官网:https://www.npmjs.com/package/query-string

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM