当前位置:网站首页>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
边栏推荐
- Codeforces gr19 D (think more about why the first-hand value range is 100, JLS yyds)
- Uniapp development, packaged as H5 and deployed to the server
- 如何解决ecology9.0执行导入流程流程产生的问题
- [EI conference sharing] the Third International Conference on intelligent manufacturing and automation frontier in 2022 (cfima 2022)
- 如何制作自己的機器人
- LeetCode 6005. The minimum operand to make an array an alternating array
- NLP text processing: lemma [English] [put the deformation of various types of words into one form] [wet- > go; are- > be]
- MySQL storage engine
- MySql——CRUD
- What is information security? What is included? What is the difference with network security?
猜你喜欢
LeetCode 1598. Folder operation log collector
[groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)
The relationship between FPGA internal hardware structure and code
Basic introduction and source code analysis of webrtc threads
如何制作自己的机器人
Calculate sha256 value of data or file based on crypto++
notepad++正則錶達式替換字符串
Key structure of ffmpeg - avframe
Notepad + + regular expression replace String
从 1.5 开始搭建一个微服务框架——调用链追踪 traceId
随机推荐
MYSQL GROUP_ The concat function realizes the content merging of the same ID
Arduino六足机器人
KDD 2022 | 脑电AI助力癫痫疾病诊断
Ffmpeg learning - core module
[groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)
Global and Chinese markets of POM plastic gears 2022-2028: Research Report on technology, participants, trends, market size and share
Leetcode 44 Wildcard matching (2022.02.13)
Model analysis of establishment time and holding time
Solve the problem of reading Chinese garbled code in sqlserver connection database
AtCoder Beginner Contest 254【VP记录】
MIT博士论文 | 使用神经符号学习的鲁棒可靠智能系统
FFmpeg抓取RTSP图像进行图像分析
[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)
Spark SQL UDF function
Idea远程提交spark任务到yarn集群
STM32按键消抖——入门状态机思维
Priority queue (heap)
Global and Chinese market of digital serial inverter 2022-2028: Research Report on technology, participants, trends, market size and share
Folding and sinking sand -- weekly record of ETF
Single source shortest path exercise (I)