焊接日报
This commit is contained in:
+22
-2
@@ -137,11 +137,31 @@ export function request(options) {
|
||||
}
|
||||
|
||||
// GET 快捷方法
|
||||
export function get(url, params = {}) {
|
||||
export const get = (url, params = {}) => {
|
||||
return request({ url, method: 'GET', data: params })
|
||||
}
|
||||
|
||||
// POST 快捷方法
|
||||
export function post(url, data = {}) {
|
||||
export const post = (url, data = {}) => {
|
||||
return request({ url, method: 'POST', data })
|
||||
}
|
||||
|
||||
|
||||
export const getUrlParam = (url, name) => {
|
||||
if (!url || !name) return null;
|
||||
|
||||
// 构造正则:匹配 ?name= 或 &name= 后面的值
|
||||
// [?&] : 匹配起始分隔符
|
||||
// ${name}: 匹配具体的参数名
|
||||
// = : 匹配等号
|
||||
// ([^&]*) : 捕获组,匹配直到下一个 & 或字符串结束的内容
|
||||
const regex = new RegExp(`[?&]${name}=([^&]*)`, 'i'); // 'i' 表示忽略大小写
|
||||
|
||||
const match = url.match(regex);
|
||||
|
||||
if (match && match[1]) {
|
||||
return decodeURIComponent(match[1]);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
Reference in New Issue
Block a user