utils工具函数之清空地址栏参数

该文章介绍了一个JavaScript函数clearUrlQuery,用于在页面跳转后清除URL中的查询参数,以避免页面刷新时因参数存在而重复执行某些操作。通过split方法获取URL的基础部分,并使用history.pushState进行无刷新更新。

问题

携带参数进行跳转后,参数需要清空,防止刷新重复执行。

function clearUrlQuery() {
   
   
  const url = window.location.href
  const valiable = url.split('?')[0]
  window.
import Vue from 'vue' import App from './App.vue' import router from './router' import store from './store' import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; Vue.use(ElementUI); //导入封装信息确认提示框组件脚本 import $myConfirm from '@/utils/my-confirm' Vue.prototype.$myConfirm = $myConfirm; //导入清空表单工具 import resetForm from '@/utils/reset-form' Vue.prototype.$resetForm = resetForm; //导入快速复制对象工具,用于数据回显 import objCopy from '@/utils/obj-copy' Vue.prototype.$objCopy = objCopy; // 全局函数及变量 import Global from './Global'; Vue.use(Global); import Axios from 'axios'; Vue.prototype.$axios = Axios; // 全局请求拦截器 Axios.interceptors.request.use( config => { return config; }, error => { // 跳转error页面 router.push({ path: "/error" }); return Promise.reject(error); } ); // 全局响应拦截器 Axios.interceptors.response.use( res => { if (res.data.code === "401") { // 401表示没有登录 // 提示没有登录 Vue.prototype.notifyError(res.data.msg); // 修改vuex的showLogin状态,显示登录组件 store.dispatch("setShowLogin", true); } if (res.data.code === "500") { // 500表示服务器异常 // 跳转error页面 router.push({ path: "/error" }); } return res; }, error => { // 跳转error页面 router.push({ path: "/error" }); return Promise.reject(error); } ); // 全局拦截器,在进入需要用户权限的页面前校验是否已经登录 router.beforeResolve((to, from, next) => { let cookie = document.cookie.match(new RegExp("(^| )"+ "XM_TOKEN" +"=([^;]*)(;|$)")); // const loginUser = store.state.user.user; // 判断路由是否设置相应校验用户权限 // console.log(to) // console.log(store) if (to.meta.requireAuth) { // console.log(loginUser) if (!cookie) { // console.log(1) // 没有登录,显示登录组件 store.dispatch("setShowLogin", true); if (from.name == null) { //此时,是在页面没有加载,直接在地址栏输入链接,进入需要登录验证的页面 next("/"); return; } // 终止导航 next(false); return; } } next(); }); // 相对时间过滤器,把时间戳转换成时间 // 格式: 2020-02-25 21:43:23 Vue.filter('dateFormat', (dataStr) => { var time = new Date(dataStr); function timeAdd0 (str) { if (str < 10) { str = '0' + str; } return str; } var y = time.getFullYear(); var m = time.getMonth() + 1; var d = time.getDate(); var h = time.getHours(); var mm = time.getMinutes(); var s = time.getSeconds(); return y + '-' + timeAdd0(m) + '-' + timeAdd0(d) + ' ' + timeAdd0(h) + ':' + timeAdd0(mm) + ':' + timeAdd0(s); }); //全局组件 import MyMenu from './components/MyMenu'; Vue.component(MyMenu.name, MyMenu); import MyList from './components/MyList'; Vue.component(MyList.name, MyList); import MyLogin from './components/MyLogin'; Vue.component(MyLogin.name, MyLogin); import MyRegister from './components/MyRegister'; Vue.component(MyRegister.name, MyRegister); Vue.config.productionTip = false; new Vue({ router, store, render: h => h(App) }).$mount('#app')
最新发布
06-02
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值