当前位置:网站首页>The detailed page returns to the list and retains the original position of the scroll bar
The detailed page returns to the list and retains the original position of the scroll bar
2022-07-06 00:37: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: ' Journalism 1', desc: ' Journalism 1' },
{ id: 2, title: ' Journalism 2', desc: ' Journalism 2' },
{ id: 3, title: ' Journalism 3', desc: ' Journalism 3' },
{ id: 4, title: ' Journalism 4', desc: ' Journalism 4' },
{ id: 5, title: ' Journalism 5', desc: ' Journalism 5' },
{ id: 6, title: ' Journalism 6', desc: ' Journalism 6' },
{ id: 7, title: ' Journalism 7', desc: ' Journalism 7' },
{ id: 8, title: ' Journalism 8', desc: ' Journalism 8' },
{ id: 9, title: ' Journalism 9', desc: ' Journalism 9' },
{ id: 10, title: ' Journalism 10', desc: ' Journalism 10' },
{ id: 11, title: ' Journalism 11', desc: ' Journalism 11' },
{ id: 12, title: ' Journalism 12', desc: ' Journalism 12' },
{ id: 13, title: ' Journalism 13', desc: ' Journalism 13' },
{ id: 14, title: ' Journalism 14', desc: ' Journalism 14' },
{ id: 15, title: ' Journalism 15', desc: ' Journalism 15' }
]
}
},
beforeRouteLeave(to, from, next) {
console.log(' Activate beforeRouteLeave route ')
// }
this.scroll = this.$refs.listBox.scrollTop
console.log(this.scroll)
next()
},
activated() {
console.log(' Activate activated Hook function ')
this.$refs.listBox.scrollTop = this.scroll
}
}
</script>
beforeRouteLeave
activated
beforeRouteLeave
activated
边栏推荐
- Power query data format conversion, Split Merge extraction, delete duplicates, delete errors, transpose and reverse, perspective and reverse perspective
- Ffmpeg learning - core module
- Yolov5、Pycharm、Anaconda环境安装
- OS i/o devices and device controllers
- KDD 2022 | 脑电AI助力癫痫疾病诊断
- PHP determines whether an array contains the value of another array
- 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
- 【线上小工具】开发过程中会用到的线上小工具合集
- Reading notes of the beauty of programming
- For a deadline, the IT fellow graduated from Tsinghua suddenly died on the toilet
猜你喜欢
Spark AQE
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
2022-02-13 work record -- PHP parsing rich text
MySQL functions
[EI conference sharing] the Third International Conference on intelligent manufacturing and automation frontier in 2022 (cfima 2022)
Idea远程提交spark任务到yarn集群
如何制作自己的機器人
About the slmgr command
AtCoder Beginner Contest 254【VP记录】
Model analysis of establishment time and holding time
随机推荐
Notepad + + regular expression replace String
State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
Folding and sinking sand -- weekly record of ETF
免费的聊天机器人API
[simple implementation of file IO]
Single source shortest path exercise (I)
FFmpeg抓取RTSP图像进行图像分析
Codeforces Round #804 (Div. 2)【比赛记录】
uniapp开发,打包成H5部署到服务器
MySql——CRUD
Model analysis of establishment time and holding time
PHP determines whether an array contains the value of another array
Power query data format conversion, Split Merge extraction, delete duplicates, delete errors, transpose and reverse, perspective and reverse perspective
7.5 decorator
Idea远程提交spark任务到yarn集群
How spark gets columns in dataframe --column, $, column, apply
STM32按键消抖——入门状态机思维
Extension and application of timestamp
Key structure of ffmpeg -- AVCodecContext
MySQL functions