当前位置:网站首页>常用工具函数 持续更新
常用工具函数 持续更新
2022-07-28 09:01:00 【织_网】
只刷新一次页面
/** * @paramstr 刷新一次 */
export const refreshOnce = (hrefUrl) => {
let url = hrefUrl //把当前页面的地址赋给变量 url
const times = url.split('?') //分切变量 url 分隔符号为 “?”
if (times[1] != 1) {
//如果?后的值不等于1表示没有刷新
url += '?1' //把变量 url 的值加入 ?1
self.location.replace(url) //刷新页面
}
}
页面使用
import {
refreshOnce } from '@/utils'
refreshOnce(location.href)
获取url参数对象
/** * @paramstr 获取url参数对象 */
export const parseQueryString = (url: string) => {
// 编写代码实现
// 1.查找?的下标
const index = url.indexOf('?')
// 2.截取?后面的字符串
const str = url.slice(index + 1)
// 3.根据&将字符串转成数组
const arr = str.split('&')
// 4. 声明对象用来存储信息
const obj = {
}
for (let i = 0; i < arr.length; i++) {
// arr[0] action=home
const arr2 = arr[i].split('=')
// arr2的第一个成员做属性, 第二个成员做值
obj[arr2[0]] = arr2[1]
}
return obj
}
页面使用
import {
parseQueryString } from '@/utils'
const hrefUrl = window.location.href
const {
mall } = parseQueryString(hrefUrl)
if (mall == 1) {
// 跳转到另一个项目的使用 开发,测试,正式
if (process.env.VITE_USER_NODE_ENV == 'development') {
window.location.href = `http://XXX.XXX.XXX.XXX:8081/#/admin/shop?token=${
res.result.token}`
} else {
hrefUrl.indexOf('test') != -1
? (window.location.href = `测试前缀/#/admin/shop?token=${
res.result.token}`)
: (window.location.href = `正式前缀/#/admin/shop?token=${
res.result.token}`)
}
return
}
边栏推荐
- 【广西大学】考研初试复试资料分享
- An entry artifact tensorflowplayground
- sql server 的关键字在哪张系统表?
- MySQL 8.0.30 GA
- Conditions and procedures of stock index futures account opening
- Network engineering -- ranking of Chinese universities in Soft Science
- Final keyword and enumeration type
- Introduction to shardingsphere's concept of sub database and sub table (2)
- Promise实例如何解决地狱回调
- [high number] high number plane solid geometry
猜你喜欢

2022 safety officer-b certificate examination simulated 100 questions and answers
![Magic brace- [group theory] [Burnside lemma] [matrix fast power]](/img/cf/606d1bc7cd877771afbdd7640b718c.png)
Magic brace- [group theory] [Burnside lemma] [matrix fast power]

oracle 创建用户且只有查询权限

Bluetooth technology | the total scale of charging piles in Beijing will reach 700000 in 2025. Talk about the indissoluble relationship between Bluetooth and charging piles

RGB-T追踪——【多模态融合】Visible-Thermal UAV Tracking: A Large-Scale Benchmark and New Baseline

21天学习挑战赛-《Autosar从入门到精通-实战篇》

正负数值的正则表达式

【广西大学】考研初试复试资料分享

Salted fish esp32 instance - mqtt lit LED

Magic Bracelet-【群论】【Burnside引理】【矩阵快速幂】
随机推荐
Express builds a simple local background (1)
【C语言】详解顺序表(SeqList)
oracle 创建用户且只有查询权限
OpenShift 4 之AMQ Streams(1) - 多个Consumer从Partition接收数据
ECCV 2022 | 无需微调即可推广!基于配准的少样本异常检测框架
Salted fish esp32 instance - mqtt lit LED
Bluetooth technology | the total scale of charging piles in Beijing will reach 700000 in 2025. Talk about the indissoluble relationship between Bluetooth and charging piles
CakePHP 4.4.3 发布,PHP 快速开发框架
MySQL 8.0.30 GA
DN-DETR 论文精度,并解析其模型结构 & 2022年CVPR论文
RGB-T追踪——【多模态融合】Visible-Thermal UAV Tracking: A Large-Scale Benchmark and New Baseline
Database core system
【广西大学】考研初试复试资料分享
2022牛客多校第一场补题
What is the difference between these two sets of code?
【解决】ERROR in [eslint] ESLint is not a constructor
The maximum recommended number of rows for MySQL is 2000W. Is it reliable?
Final keyword and enumeration type
2022 safety officer-b certificate examination simulated 100 questions and answers
ActivityRouter源码解析