fix: fixed param2Obj.spec.js
This commit is contained in:
parent
4958db1bad
commit
b292e46f45
@ -1,21 +1,14 @@
|
|||||||
/**
|
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
|
})
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user