vue.js - 防止在历史记录中加载初始数据
问题描述
有Home.vue
和Statistics.vue
页。Home.vue
渲染TableFields.vue
组件。在Home.vue
页面加载时设置了初始值“3”的数字。设置间隔函数每两秒添加和计算一次数字。如何实现这些计算出来的数字在从首页到统计页面并向后移动后保持不变,并且只有在页面刷新后才重置?路由器index.js
文件:
import Vue from 'vue'
import VueRouter from 'vue-router'
import TableFields from '../components/TableFields.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'Home',
component: TableFields
},
{
path: '/statistics',
name: 'Statistics',
// route level code-splitting
// this generates a separate chunk (statistic.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "statistic" */ '../views/Statistics.vue')
}
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
export default router
应用程序.vue 文件:
<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/statistics">Statistics</router-link>
</div>
<router-view :changesA.sync="changesA" :changesB.sync="changesB" />
</div>
</template>
项目回购:链接
解决方案
一种方法是使用keep-alive
组件到router-view
组件:
在你的 App.vue 中:
<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/statistics">Statistics</router-link>
</div>
<keep-alive>
<router-view :changesA.sync="changesA" :changesB.sync="changesB" />
</keep-alive>
</div>
</template>
推荐阅读
- apache-spark - 如何确保 Spark 数据源 v2 中的数据局部性?
- c# - 使用循环c#发送多封电子邮件时出现未指定的错误
- javascript - 带有拖放缩进的 Jquery 可排序
- python - 将交换文件夹擦除到指定大小
- c# - C#如何将图片框的点击事件结合到相应的函数中?
- javascript - 页面重新加载时的Javascript倒计时问题
- reactjs - 如何使用 Office Fabric 和 microsoft graph API 将人员加载为打字
- xml - 带有子节点的 Oracle XML 层次结构 (NEWCONTEXTFROMHIERARCHY)
- snmp - Opendaylight WebGUI 不可视化 SNMP 设备的拓扑/节点信息
- javascript - 如何在单击图标播放/暂停时打开音频