在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