小豪豪
小豪豪
  • 发布:2021-07-31 21:38
  • 更新:2022-07-12 21:50
  • 阅读:2638

uni-app 中 h5怎么使用 Keep-Alive 呢?

分类:uni-app

uni-app 中 h5怎么使用 Keep-Alive 呢?

2021-07-31 21:38 负责人:无 分享
已邀请:
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>  

该问题目前已经被锁定, 无法添加新回复