vue 4 dynamic components (components), and 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'"><>Button</Display assembly hello
        Button @click = "In Flag = 'My-world'" > Show world assembly </ Button >


        < Div > 
            <-! Using a keep-alive Cache components of inactive components, can hold, avoid re-rendering, the default every time the destruction of inactive components and re-created -> 
            < keep-alive > 
                < the Component : IS = " In Flag " > </ Component >     
            </ Keep-Alive > 
        </ div > 
    </ div >

    <script>
        var vm=new Vue({
            el: ' #itany '
            data:{
                flag:'my-hello'
            },
            components:{
                'my-hello':{
                    Template: ' <H3> I hello components: {X} {} </ H3> ' ,
                    data(){
                        return {
                            x:Math.random()
                        }
                    }
                },
                'my-world':{
                    Template: ' <H3> I world components: {{Y}} </ H3> ' ,
                    data(){
                        return {
                            y:Math.random()
                        }
                    }
                }
            }
        });    
    </script>
</body>
</html>

 

Guess you like

Origin www.cnblogs.com/xiaobaicai123/p/11995717.html
Recommended