美文网首页
vue 解决key属性2.0

vue 解决key属性2.0

作者: coderhzc | 来源:发表于2021-03-25 23:19 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>2.class类名的使用</title>
        <script src='./js/vue.js'></script>
        <style>
            .active {
                color: red;
            }
            
            .error {
                font-size: 30px;
                font-weight: bold;
            }
        </style>
    </head>
    
    <body>
        <div id="root">
            <template v-if="type === 'name'">
                <label>用户名:</label>
                <input type="text" placeholder="请输入用户名" key="name">
            </template>
    
            <template v-if="type === 'mail'">
                <label>邮箱:</label>
                <input type="text" placeholder="请输入用户名" key="mail">
            </template>
    
            <button @click="BtnClickChange"> 点击切换 </button>
        </div>
        <script>
            var app = new Vue({
                el: "#root",
                data() {
                    return {
                        type: "name"
                    }
                },
                methods: {
                    BtnClickChange() {
                        setTimeout(() => {
                            this.type = this.type === "name" ? "mail" : "name"
                        }, 1000)
                    }
                }
            })
        </script>
    </body>
    
    </html>

    相关文章

      网友评论

          本文标题:vue 解决key属性2.0

          本文链接:https://www.haomeiwen.com/subject/wksdhltx.html