From 5dd62efed1f7838c4351a3850d932316988782dc Mon Sep 17 00:00:00 2001 From: Pan Date: Fri, 19 Apr 2019 21:55:03 +0800 Subject: [PATCH] perf[utils]: add param2Obj function --- src/utils/index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/utils/index.js b/src/utils/index.js index f18fccb..cd14bd5 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -88,3 +88,23 @@ export function formatTime(time, option) { ) } } + +/** + * @param {string} url + * @returns {Object} + */ +export function param2Obj(url) { + const search = url.split('?')[1] + if (!search) { + return {} + } + return JSON.parse( + '{"' + + decodeURIComponent(search) + .replace(/"/g, '\\"') + .replace(/&/g, '","') + .replace(/=/g, '":"') + .replace(/\+/g, ' ') + + '"}' + ) +}