File tree Expand file tree Collapse file tree 1 file changed +13
-20
lines changed Expand file tree Collapse file tree 1 file changed +13
-20
lines changed Original file line number Diff line number Diff line change 1
- /**
2
- * @param {string } url
3
- * @returns {Object }
4
- */
5
- export function param2Obj ( url ) {
6
- const search = decodeURIComponent ( url . split ( '?' ) [ 1 ] ) . replace ( / \+ / g, ' ' )
7
- if ( ! search ) {
8
- return { }
9
- }
10
- const obj = { }
11
- const searchArr = search . split ( '&' )
12
- searchArr . forEach ( v => {
13
- const index = v . indexOf ( '=' )
14
- if ( index !== - 1 ) {
15
- const name = v . substring ( 0 , index )
16
- const val = v . substring ( index + 1 , v . length )
17
- obj [ name ] = val
18
- }
1
+ import { param2Obj } from '@/utils/index.js'
2
+ describe ( 'Utils:param2Obj' , ( ) => {
3
+ const url = 'https://github.com/PanJiaChen/vue-element-admin?name=bill&age=29&sex=1&field=dGVzdA==&key=%E6%B5%8B%E8%AF%95'
4
+
5
+ it ( 'param2Obj test' , ( ) => {
6
+ expect ( param2Obj ( url ) ) . toEqual ( {
7
+ name : 'bill' ,
8
+ age : '29' ,
9
+ sex : '1' ,
10
+ field : window . btoa ( 'test' ) ,
11
+ key : '测试'
12
+ } )
19
13
} )
20
- return obj
21
- }
14
+ } )
You can’t perform that action at this time.
0 commit comments