当前位置:网站首页>详细页返回列表保留原来滚动条所在位置
详细页返回列表保留原来滚动条所在位置
2022-07-06 00:33:00 【InfoQ】
meta
import Vue from 'vue'
import VueRouter from 'vue-router'
import News from '../views/News'
import New from '../components/new'
Vue.use(VueRouter)
const routes = [{
path: '/',
component: News,
meta: { keepAlive: true }
}, {
path: '/new/:id',
component: New
}]
keepAlive
keepAlive
<template>
<div id="app">
<keep-alive>
<router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive"></router-view>
</div>
</template>
keepAlive
<template>
<div id="news" ref="listBox">
<ul>
<li v-for=" newa in news" :key="newa.id">
<router-link :to="'/new/' +newa.id">{{newa.title}}</router-link>
</li>
</ul>
<router-view></router-view>
</div>
</template>
<script>
export default {
name: 'news',
data() {
return {
scroll: 0,
news: [
{ id: 1, title: '新闻1', desc: '新闻1' },
{ id: 2, title: '新闻2', desc: '新闻2' },
{ id: 3, title: '新闻3', desc: '新闻3' },
{ id: 4, title: '新闻4', desc: '新闻4' },
{ id: 5, title: '新闻5', desc: '新闻5' },
{ id: 6, title: '新闻6', desc: '新闻6' },
{ id: 7, title: '新闻7', desc: '新闻7' },
{ id: 8, title: '新闻8', desc: '新闻8' },
{ id: 9, title: '新闻9', desc: '新闻9' },
{ id: 10, title: '新闻10', desc: '新闻10' },
{ id: 11, title: '新闻11', desc: '新闻11' },
{ id: 12, title: '新闻12', desc: '新闻12' },
{ id: 13, title: '新闻13', desc: '新闻13' },
{ id: 14, title: '新闻14', desc: '新闻14' },
{ id: 15, title: '新闻15', desc: '新闻15' }
]
}
},
beforeRouteLeave(to, from, next) {
console.log('激活beforeRouteLeave路由')
// }
this.scroll = this.$refs.listBox.scrollTop
console.log(this.scroll)
next()
},
activated() {
console.log('激活activated钩子函数')
this.$refs.listBox.scrollTop = this.scroll
}
}
</script>
beforeRouteLeave
activated
beforeRouteLeave
activated
边栏推荐
- The global and Chinese markets of dial indicator calipers 2022-2028: Research Report on technology, participants, trends, market size and share
- Spark DF adds a column
- Leetcode Fibonacci sequence
- Huawei equipment is configured with OSPF and BFD linkage
- Spark获取DataFrame中列的方式--col,$,column,apply
- Key structure of ffmpeg -- AVCodecContext
- 剖面测量之提取剖面数据
- Atcoder beginer contest 258 [competition record]
- Idea remotely submits spark tasks to the yarn cluster
- Location based mobile terminal network video exploration app system documents + foreign language translation and original text + guidance records (8 weeks) + PPT + review + project source code
猜你喜欢
Search (DFS and BFS)
N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2
Spark SQL空值Null,NaN判断和处理
Start from the bottom structure and learn the introduction of fpga---fifo IP core and its key parameters
Ffmpeg captures RTSP images for image analysis
如何解决ecology9.0执行导入流程流程产生的问题
FFmpeg抓取RTSP图像进行图像分析
Spark SQL null value, Nan judgment and processing
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
Hudi of data Lake (2): Hudi compilation
随机推荐
LeetCode 6004. Get operands of 0
云导DNS和知识科普以及课堂笔记
[QT] QT uses qjson to generate JSON files and save them
Room cannot create an SQLite connection to verify the queries
Extracting profile data from profile measurement
Hudi of data Lake (1): introduction to Hudi
Calculate sha256 value of data or file based on crypto++
【DesignMode】装饰者模式(Decorator pattern)
MDK debug时设置数据实时更新
时间戳的拓展及应用实例
Key structure of ffmpeg - avformatcontext
Tools to improve work efficiency: the idea of SQL batch generation tools
Yolov5, pychar, Anaconda environment installation
Classic CTF topic about FTP protocol
【DesignMode】组合模式(composite mode)
免费的聊天机器人API
Permission problem: source bash_ profile permission denied
《编程之美》读书笔记
About the slmgr command
Spark AQE