From 9e678d108c5694858f10dc970845ce9d2df31435 Mon Sep 17 00:00:00 2001 From: xiaoronghao <1300399510@qq.com> Date: Fri, 7 Apr 2023 18:42:46 +0800 Subject: [PATCH] =?UTF-8?q?=C2=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 3 +- src/utils/common.js | 12 +++++++- src/views/detail/detailIndex.vue | 12 ++++---- src/views/index/allSections/AllSections.vue | 30 +++++++++++-------- src/views/index/index.vue | 12 ++++++-- src/views/index/recommend/Recommend.vue | 14 +++++---- src/views/search/search.vue | 8 ++++- .../search/searchResult/SearchResult.vue | 15 +++++++--- 8 files changed, 74 insertions(+), 32 deletions(-) diff --git a/src/main.js b/src/main.js index 8881831..56f9b90 100755 --- a/src/main.js +++ b/src/main.js @@ -4,7 +4,7 @@ import router from './router' import store from './store' import ElementUI, { Message, Pagination, loading } from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; -import { skipUrl, pageStop, pageMove, goTologin, copy, startupUnderLoading, closeUnderLoading, formattedDate } from "@/utils/common.js" +import { skipUrl, pageStop, pageMove, goTologin, copy, startupUnderLoading, closeUnderLoading, formattedDate, updateURLSearchParams } from "@/utils/common.js" import http from "@/utils/request" import hintBox from '@/components/Hintbox' @@ -26,6 +26,7 @@ Vue.prototype.$copy = copy // 复制 Vue.prototype.$startupUnderLoading = startupUnderLoading // 开启加载提示 element的 Vue.prototype.$closeUnderLoading = closeUnderLoading // 关闭加载提示 element的 Vue.prototype.$formattedDate = formattedDate // 时间戳转格式 +Vue.prototype.$updateURLSearchParams = updateURLSearchParams // 不刷新的情况下修改url //svg文件引入 import './icons' diff --git a/src/utils/common.js b/src/utils/common.js index 7d76c26..80c0b26 100755 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -73,4 +73,14 @@ function formattedDate(timestamp) { return formattedDate } -export { skipUrl, pageStop, pageMove, goTologin, copy, startupUnderLoading, closeUnderLoading, formattedDate } \ No newline at end of file +// 不刷新的情况下修改url +function updateURLSearchParams(obj = {}) { + const params = new URLSearchParams(window.location.search); + for (const key in obj) { + params.set(key, obj[key]); + } + const newUrl = window.location.pathname + '?' + params.toString(); + window.history.pushState({}, '', newUrl); +} + +export { skipUrl, pageStop, pageMove, goTologin, copy, startupUnderLoading, closeUnderLoading, formattedDate, updateURLSearchParams } \ No newline at end of file diff --git a/src/views/detail/detailIndex.vue b/src/views/detail/detailIndex.vue index 28c4227..8d101fe 100755 --- a/src/views/detail/detailIndex.vue +++ b/src/views/detail/detailIndex.vue @@ -20,7 +20,7 @@