1、创建函数文件getUrlParams.js
const getUrlParams = (url, key) => {
const search = new URL(url).search;
const params = new URLSearchParams(search);
return params.get(key);
};
export { getUrlParams };
2、目标文件引入并使用
import { getUrlParams } from '../../../utils/getUrlParams';
const search = window.location;
const codeAttributerType = getUrlParams(search, 'codeAttributerType');
const coder = getUrlParams(search, 'coder');