zoukankan      html  css  js  c++  java
  • vue条件渲染

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
        </head>
        <body>
            <div id="app">
                <h1>{{ isLogin ? '登录' : '注册' }}</h1>
                
                <form action="" v-if='isLogin' >
                    <input type="text" placeholder="请输入用户名" />
                    <input type="password" placeholder="请输入密码" />
                    <input type="submit" name="" id="" value="登录" />
                </form>
                
                <form action="" v-if='!isLogin'>
                    <input type="text" placeholder="请输入用户名" />
                    <input type="password" placeholder="请输入密码" />
                    <input type="password" placeholder="请再次输入密码" />
                    <input type="submit" name="" id="" value="注册" />
                </form>
                
                <hr />
                <hr />
                
                <form action="" v-show='isLogin' >
                    <input type="text" placeholder="请输入用户名" />
                    <input type="password" placeholder="请输入密码" />
                    <input type="submit" name="" id="" value="登录" />
                </form>
                
                <form action="" v-show='!isLogin'>
                    <input type="text" placeholder="请输入用户名" />
                    <input type="password" placeholder="请输入密码" />
                    <input type="password" placeholder="请再次输入密码" />
                    <input type="submit" name="" id="" value="注册" />
                </form>
                <!--
                    条件渲染:
                    v-if:在只渲染一次的情况下,那么性能最佳
                    v-show:在频繁切换的情况下,那么性能最佳,因为v-show,所有都生成出来,通过display来决定是否显示
                    
                -->
                <button @click='login'>登录</button>
                <button @click='register'>注册</button>
            </div>
            
            
            <script type="text/javascript">
                var app = new Vue({
                    el:'#app',
                    data:{
                        isLogin:true
                    },
                    methods:{
                        register:function(){
                            this.isLogin = false
                        },
                        login:function(){
                            this.isLogin = true
                        }
                    }
                })
            </script>
        </body>
    </html>
  • 相关阅读:
    1. Dubbo原理解析-Dubbo内核实现之SPI简单介绍 (转)
    经典算法问题的java实现 (二)
    经典算法问题的java实现 (一)
    Bitmap的秘密
    Java Networking: UDP DatagramSocket (翻译)
    Java字节码浅析(二)
    Sql server 浅谈用户定义表类型
    Jquery 动态生成表单 并将表单数据 批量通过Ajax插入到数据库
    ASP.NET获取上传图片的大小
    ASP.Net大文件上传组件详解
  • 原文地址:https://www.cnblogs.com/wwthuanyu/p/10554833.html
Copyright © 2011-2022 走看看