4***@qq.com
4***@qq.com
  • 发布:2022-07-12 18:04
  • 更新:2023-03-28 13:55
  • 阅读:536

页面A跳转到页面A怎么实现 (keep-alive router-view)

分类:uni-app

请问页面A跳转到页面A怎么实现缓存页面;
页面A:由动态组件生成的页面
类似vue的

<keep-alive>  
      <router-view :key="$route.fullPath"/>  
    </keep-alive>
2022-07-12 18:04 负责人:无 分享
已邀请:
DCloud_UNI_WZF

DCloud_UNI_WZF

参考如下代码:

<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

不想起昵称

不想起昵称 - 没啥介绍

不支持app有个吊用

要回复问题请先登录注册