Vue的登陆注册切换

Vue的登陆注册切换

  • Vue的登录注册切换可通过v-ifv-else实现(样式有点丑–手动狗头)
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue的登陆注册切换</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <style>
        #app {
    
    
           display: flex;
           flex-direction: column;
        }
        #y{
    
    
            display: flex;
            justify-content: center;
            align-content: center;
        }
        #y div{
    
    
            text-align: center;
        }
        #z{
    
    
            width: 500px;
            height: 250px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="app">
        <div id="y">
            <div id="z" v-if="isShow">
                用户名:<input type="text" value="">
                <br/>
                密码:<input type="text" value="">
             </div>
             <div id="z" v-else>
                 用户名:<input type="text" value="">
                 <br/>
                 密码:<input type="text" value="">
                 <br/>
                 密码:<input type="text" value="">
             </div>
        </div>
        <div id="y">
            <button @click="logo">登录</button>
            <button @click="register">注册</button>
        </div>
    </div>
    <script>
        var app = new Vue({
    
    
            el: '#app',
            data: {
    
    
                isShow: true
            },
            methods: {
    
    
                logo(){
    
    
                    this.isShow = true
                },
                register(){
    
    
                    this.isShow = false
                }
            }
        })
    </script>
</body>
</html>

最后附上效果图
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_50480451/article/details/125986404