vue project this. $router. go (- 1) can‘t goback

在Vue项目里使用`this.$router.go(-1)`进行历史记录回退时,遇到一个问题:点击按钮后URL出现'?'字符,导致前一页加载失败。双击后才生效,但URL出现错误。原始URL为'http://localhost/payment/#/certification/detail',回退后变为'http://localhost/payment/?#/certification/detail'。问题出现在按钮的 goback() 函数中,可能与路由配置有关。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In the Vue project, hash route ‘this. $router. go (- 1)’ is used, and click button the url ‘#’ before has a ‘?’ & Causes the previous page to fail , double click It will take effect but url err
this origin url
http://localhost/payment/#/certification/detail
if i click goback the url change
http://localhost/payment/?#/certification/detail
my code
//button
<button class="btn back p-cu-p" @click="goback">GoBack</button>

//function
goback () {

this.$router.go(-1)

},

//route
{

path: '/certification',
name: 'CertifictionIndex',
component: () => import('@/views/CustomerManagement/certificationIndex.vue'),
children: [
{
path: '/',
name: 'Certifiction',
component: () => import('@/views/CustomerManagement/certification.vue'),
},
{
path: 'detail',
name: 'CertifictionDetail',
component: () => import('@/views/CustomerManagement/certificationDetail.vue'),
},
],
}
<!-- * @Author: luoxianbo combatzone@163.com * @Date: 2025-07-12 20:23:28 * @LastEditors: luoxianbo combatzone@163.com * @LastEditTime: 2025-08-03 16:32:25 * @FilePath: \VUE3-PROJECT\vite-project\src\components\tecHigLin\TecHigligInfo.vue * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE --> <template> <div class="parent-div"> <div class="left-cloums-div" v-show="leftShowFlag"> <div class="main-div"> <div> <h2>详细介绍</h2> </div> <div class="main-info-div"> <p> <span class="span-title">id </span> <span class="span-message">{{ tecDetil.id }}</span> </p> <p> <span class="span-title">名称 </span> <span class="span-message">{{ tecDetil.name }}</span> </p> <p> <span class="span-title">模块id </span> <span class="span-message">{{ tecDetil.type }}</span> </p> <p> <span class="span-title">模块名称 </span> <span class="span-message">{{ tecDetil.typeName }}</span> </p> <span class="span-title">内容</span> <div class="message-div" v-html="tecDetil.techigligmessage"></div> <div> <button class="gobackBt" @click="goBack">返回</button> </div> </div> </div> <div class="small-list-div"> <div class="small-list-div-div">子项目清单</div> <div class="list-div" id="listContainer"></div> </div> </div> <div class="right-cloums-div" v-show="!leftShowFlag"> <div class="small-list-div"> <div class="small-list-div-div">子项目清单</div> <div class="list-div" id="listContainer"></div> </div> <div class="small-detil-div">详情页面</div> </div> </div> </template> <script setup> import technologyTypeApi from "../../api/technologyTypeIndex.js"; import "@vueup/vue-quill/dist/vue-quill.snow.css"; import { ref, onMounted } from "vue"; //缓存内容引入 import { useRoute, useRouter } from "vue-router"; //详情接口返回数据承接声明 const tecDetil = ref({ id: "", name: "", type: "", typeName: "", techigligmessage: "", smalltecVOList: [], // 初始化为空数组 }); // 路由信息对象 const route = useRoute(); const router = useRouter(); const leftShowFlag = ref(true); //组件渲染函数 onMounted(() => { //调用详情接口函数 getTecDetil(route.params.id); }); //获取详情接口调用函数 const getTecDetil = (id) => { //情趣详情接口 technologyTypeApi.detail({ id: id }).then((res) => { tecDetil.value = res.data.data; const smallTecList = res.data.data.smalltecVOList || []; console.log(typeof smallTecList); // 1. 获取列表容器 const listContainer = document.getElementById("listContainer"); // 2. 清空现有内容 listContainer.innerHTML = ""; let ulElement = document.createElement("ul"); ulElement.className = "el-class-name"; smallTecList.forEach((item) => { //创建ol标签 let elElement = document.createElement("ol"); elElement.innerText = item.title; elElement.addEventListener("click", () => { getSmallDetil(item.id); }); //将创建的ol标签加到ul标签中 ulElement.appendChild(elElement); }); // 4. 将ul添加到容器 listContainer.appendChild(ulElement); }); }; function getSmallDetil(id) { console.log("调用子项目详情查询接口", id); leftShowFlag.value = false; } //返回函数 const goBack = () => { router.push({ name: "TecHigligListName", }); }; </script> <style scoped lang="scss"> .left-cloums-div { display: flex; //弹性布局 justify-content: center; //水平居中 gap: 10px; //子元素间距 margin: 10px; height: 560px; } .right-cloums-div { display: flex; //弹性布局 justify-content: left; //水平居中 gap: 10px; //子元素间距 margin: 10px; height: 560px; } //子级元素布局 .main-div { flex: 1; height: 100%; } .small-list-div { flex: 0.3; height: 100%; weight: 100px; } p { margin: 10px; } .span-title { background-color: #bed2f0; font-size: 16px; //字号 font-family: Arial, sans-serif; //字体 font-weight: bold; //加粗 border: 1px solid #000; //边框 border-radius: 4px; //圆角 padding: 2px 5px; margin: 5px; } .span-message { background-color: #dde5f1; font-size: 16px; //字号 font-family: Arial, sans-serif; //字体 border: 1px solid #bdb6b6; //边框 border-radius: 4px; //圆角 padding: 2px 5px; } .message-div { background-color: rgb(163, 171, 167); margin: 5px; padding: 3px; height: 300px; width: 100%; overflow-y: auto; //当div的内容过多,则垂直滚动显示 } .small-list-div-div { background-color: #bdb6b6; width: 100%; border: 1px solid #bdb6b6; //边框 border-radius: 4px; //圆角 } .list-div { margin: 4px; width: 100%; height: 400px; } .li-class { background-color: rgb(118, 115, 115); } .gobackBt { width: 50px; height: 30px; background-color: brown; } </style> 分析这段代码,在点击left-cloums-div元素下的ol标签之后,right-cloums-div元素下的list-div列表没有数据,式什么原因,如何解决
最新发布
08-04
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值