zoukankan      html  css  js  c++  java
  • vue 4 动态组件(多个组件) 以及keep-alive

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>动态组件</title>
        <script src="js/vue.js"></script>
    </head>
    <body>
        <div id="itany">
            <button @click="flag='my-hello'">显示hello组件</button>
            <button @click="flag='my-world'">显示world组件</button>
    
    
            <div>
                <!-- 使用keep-alive组件缓存非活动组件,可以保留状态,避免重新渲染,默认每次都会销毁非活动组件并重新创建 -->
                <keep-alive>
                    <component :is="flag"></component>    
                </keep-alive>
            </div>
        </div>
    
        <script>
            var vm=new Vue({
                el:'#itany',
                data:{
                    flag:'my-hello'
                },
                components:{
                    'my-hello':{
                        template:'<h3>我是hello组件:{{x}}</h3>',
                        data(){
                            return {
                                x:Math.random()
                            }
                        }
                    },
                    'my-world':{
                        template:'<h3>我是world组件:{{y}}</h3>',
                        data(){
                            return {
                                y:Math.random()
                            }
                        }
                    }
                }
            });    
        </script>
    </body>
    </html>
  • 相关阅读:
    MinGW离线包下载地址
    词法分析器--DFA(c++实现)
    linux下shell统计文件目录下所有代码行数
    四则运算表达式
    BliBli抢楼全攻略
    python 电影下载链接爬虫
    in, out, ref
    联合查询
    SQL语句大全
    LINQ
  • 原文地址:https://www.cnblogs.com/xiaobaicai123/p/11995717.html
Copyright © 2011-2022 走看看