当前位置:网站首页>常用工具函数 持续更新
常用工具函数 持续更新
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
}
边栏推荐
- [one flower, one world - Professor Zheng Yi - the way of simplicity] interpretable neural network
- ShardingSphere之分库分表概念介绍(二)
- [gossip] the development of programmers needs two abilities most
- ActivityRouter源码解析
- express搭建一个简易的本地后台(一)
- Regular expressions for positive and negative values
- Network engineering -- ranking of Chinese universities in Soft Science
- 19c SYSAUX表空间SQLOBJ$PLAN表过大,如何清理
- [JVM] JVM refers to floating point number
- 正则表达式为十六进制数字?
猜你喜欢

2022 safety officer-b certificate examination simulated 100 questions and answers

JDBC connection database
![[package deployment]](/img/6f/93a35436947311bc2305adcb0df1a6.png)
[package deployment]

就这么一个简单的校验,80%的程序员却做不到,更不理解!

5 operators, expressions, and statements
![[Guangxi University] information sharing of postgraduate entrance examination and re examination](/img/25/e35de6b9d803c9a80e0d2816aaad87.jpg)
[Guangxi University] information sharing of postgraduate entrance examination and re examination

MATLAB的实时编辑器

对话MySQL之父:代码一次性完成才是优秀程序员

ShardingSphere简介(一)

What is cross domain? How to solve the cross domain problem?
随机推荐
C signed and unsigned byte variables
[Guangxi University] information sharing of postgraduate entrance examination and re examination
2.9.5 Ext JS的Object类型处理及便捷方法
【杂谈】程序员的发展最需要两点能力
OpenShift 4 之AMQ Streams(1) - 多个Consumer从Partition接收数据
Final keyword and enumeration type
【C语言】详解顺序表(SeqList)
ECCV 2022 | 无需微调即可推广!基于配准的少样本异常检测框架
RGB-T追踪——【多模态融合】Visible-Thermal UAV Tracking: A Large-Scale Benchmark and New Baseline
译文推荐 | 调试 BookKeeper 协议 - 无界 Ledger
How promise instance solves hell callback
2022 high voltage electrician examination simulated 100 questions and simulated examination
sql server 的关键字在哪张系统表?
MQTT. JS introductory tutorial: learning notes
MATLAB的数列与极限运算
[vscode] vscode usage
mysql 最大建议行数2000w,靠谱吗?
VR panoramic shooting helps promote the diversity of B & B
[Download] several tools for brute force cracking and dictionary generation are recommended
express搭建一个简易的本地后台(一)