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