当前位置:网站首页>详细页返回列表保留原来滚动条所在位置
详细页返回列表保留原来滚动条所在位置
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
边栏推荐
- Spark AQE
- notepad++正则表达式替换字符串
- 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
- Cloud guide DNS, knowledge popularization and classroom notes
- Basic introduction and source code analysis of webrtc threads
- Pointer pointer array, array pointer
- The relationship between FPGA internal hardware structure and code
- DEJA_ Vu3d - cesium feature set 055 - summary description of map service addresses of domestic and foreign manufacturers
- Analysis of the combination of small program technology advantages and industrial Internet
- Calculate sha256 value of data or file based on crypto++
猜你喜欢
Analysis of the combination of small program technology advantages and industrial Internet
Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)
小程序技术优势与产业互联网相结合的分析
FFMPEG关键结构体——AVCodecContext
Spark AQE
如何解决ecology9.0执行导入流程流程产生的问题
Start from the bottom structure and learn the introduction of fpga---fifo IP core and its key parameters
Calculate sha256 value of data or file based on crypto++
MySql——CRUD
Hardware and interface learning summary
随机推荐
小程序技术优势与产业互联网相结合的分析
MySQL functions
MySql——CRUD
2022.7.5-----leetcode. seven hundred and twenty-nine
Go learning --- read INI file
MySql——CRUD
Codeforces gr19 D (think more about why the first-hand value range is 100, JLS yyds)
How to make your own robot
FFMPEG关键结构体——AVCodecContext
免费的聊天机器人API
剖面测量之提取剖面数据
Global and Chinese market of digital serial inverter 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets for hinged watertight doors 2022-2028: Research Report on technology, participants, trends, market size and share
【DesignMode】组合模式(composite mode)
Extension and application of timestamp
[QT] QT uses qjson to generate JSON files and save them
MySql——CRUD
Natural language processing (NLP) - third party Library (Toolkit):allenlp [library for building various NLP models; based on pytorch]
LeetCode 6005. The minimum operand to make an array an alternating 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