实现逻辑如下:
进入当前页面的时候,页面路由为http://localhost:8080/#/problem
点击某个标签,页面路径修改为http://localhost:8080/#/problem?index=3
index的值为选中的标签下标,这样就用当前路由记录了当前的标签选中项
进入详情页后,路由为http://localhost:8080/#/detail/?id=57
返回上级页面,页面路由为http://localhost:8080/#/problem?index=3
在页面渲染的时候,获取路由的参数,获取到index的值为3
然后就将标签的选中项,设置为下标为3的标签,
同时请求下标为3的标签项对应的问题内容,填充到右侧
代码如下:
给页面路由添加index内容
//在点击标签的时候调用
this.KaTeX parse error: Expected '}', got 'EOF' at end of input: … ...this.route.query,
index: index
}
})
1
2
3
4
5
6
7
// 判断路由中是否有index
if (this.KaTeX parse error: Expected '}', got 'EOF' at end of input: …t index = this.route.query.index
// 设置标签的默认选中项
this.activeKey = index
// 获取选中项的右侧问题内容
let typeId = this.questionHeadData[index].typeId
this.oneId = typeId
this.getQuestionMore(typeId)
} else {
// 走正常的页面渲染逻辑
const typeId = this.questionHeadData[0].typeId
this.oneId = typeId
// 请求右侧数据
this.getQuestionMore(typeId)
}