Commit b292e46f authored by 花裤衩's avatar 花裤衩

fix: fixed param2Obj.spec.js

parent 4958db1b
/** import { param2Obj } from '@/utils/index.js'
* @param {string} url describe('Utils:param2Obj', () => {
* @returns {Object} const url = 'https://github.com/PanJiaChen/vue-element-admin?name=bill&age=29&sex=1&field=dGVzdA==&key=%E6%B5%8B%E8%AF%95'
*/
export function param2Obj(url) { it('param2Obj test', () => {
const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ') expect(param2Obj(url)).toEqual({
if (!search) { name: 'bill',
return {} age: '29',
} sex: '1',
const obj = {} field: window.btoa('test'),
const searchArr = search.split('&') key: '测试'
searchArr.forEach(v => {
const index = v.indexOf('=')
if (index !== -1) {
const name = v.substring(0, index)
const val = v.substring(index + 1, v.length)
obj[name] = val
}
}) })
return obj })
} })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment