请问页面A跳转到页面A怎么实现缓存页面;
页面A:由动态组件生成的页面
类似vue的
<keep-alive>
<router-view :key="$route.fullPath"/>
</keep-alive>
请问页面A跳转到页面A怎么实现缓存页面;
页面A:由动态组件生成的页面
类似vue的
<keep-alive>
<router-view :key="$route.fullPath"/>
</keep-alive>
参考如下代码:
<template>
<view>
<keep-alive :include="componentsName">
<component :is="componentsName[currentComponentIndex]"></component>
</keep-alive>
<button type="primary" @click="changeComponent">changeComponent</button>
</view>
</template>
<script>
import Foo from '../../components/Foo.vue'
import Bar from '../../components/Bar.vue'
export default {
components: {
Foo,
Bar
},
data() {
return {
componentsName: ['Foo', 'Bar'],
currentComponentIndex: 0
}
},
methods: {
changeComponent() {
this.currentComponentIndex = !this.currentComponentIndex * 1
}
}
}
</script>
4***@qq.com (作者)
3ks。这样写在浏览器上返回的话、会有问题吧
2022-07-13 10:15
DCloud_UNI_WZF
回复 4***@qq.com: 页面间回退uni-app 默认是有缓存的,比如A->B,B回退到A,A是有缓存的,keep-alive 可以用于当前页面动态组件的缓存
2022-07-13 13:09