当前位置:网站首页>常用工具函数 持续更新
常用工具函数 持续更新
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
}
边栏推荐
- QT basic hand training applet - simple calculator design (with source code, analysis)
- Pytorch deep learning practice lesson 9 multi classification problems (handwritten numeral MNIST)
- Salted fish esp32 instance - mqtt lit LED
- 2022牛客多校第一场补题
- Final keyword and enumeration type
- MATLAB的符号运算
- sql server 的关键字在哪张系统表?
- HashSet内部原理解析
- 【一花一世界-郑一教授-繁简之道】可解释神经网络
- C signed and unsigned byte variables
猜你喜欢

Activiti启报错: Cannot create PoolableConnectionFactory (Could not create connection to database server

JDBC connection database

《PyTorch深度学习实践》第九课多分类问题(手写数字MNIST)

What is cross domain? How to solve the cross domain problem?

Network engineering -- ranking of Chinese universities in Soft Science

【C语言】详解顺序表(SeqList)

正负数值的正则表达式

DN-DETR 论文精度,并解析其模型结构 & 2022年CVPR论文

How promise instance solves hell callback

IJCAI 2022 | the latest overview of graph structure learning: research progress and future prospects
随机推荐
[C language] detailed explanation sequence table (seqlist)
[autosar-rte] - introduction of 2-component, component and VFB
MySQL中各类型文件详解
QT基础练手小程序-简单计算器设计(附带源码,解析)
Which system table is the keyword of SQL Server in?
5 operators, expressions, and statements
ARouter源码解析(三)
2022 high voltage electrician examination simulated 100 questions and simulated examination
DN-DETR 论文精度,并解析其模型结构 & 2022年CVPR论文
MATLAB的数列与极限运算
【多线程】long和double的非原子性协定
2022高压电工考试模拟100题及模拟考试
2.9.5 ext JS object type processing and convenient methods
数据泄漏、删除事件频发,企业应如何构建安全防线?
《PyTorch深度学习实践》第九课多分类问题(手写数字MNIST)
数据库核心体系
《我的Vivado实战—单周期CPU指令分析》
What is it like to use gbase C API to execute stored procedures?
How promise instance solves hell callback
LeetCode_ 406_ Rebuild the queue based on height