Vue登錄方式的切換


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>登錄方式的切換</title>
    </head>
    <body>
        <div id="app">
            <template v-if="loginType==='email'">
                <label>郵箱</label>
                <input type="text" placeholder="請輸入郵箱號" />
            </template>

            <template v-else-if="loginType==='phone'">
                <label>手機號</label>
                <input type="text" placeholder="請輸入手機號" />
            </template>

            <button @click="btn">切換</button>
        </div>


        <script src="vue.js"></script>
        <script>
            new Vue({
                el: "#app",
                data: {
                    loginType: 'email'
                },
                methods: {
                    btn: function() {
                        console.log(this.loginType)
                        // 第一種方式
                        //this.loginType = (this.loginType === "email") ? 'phone' : 'email';

                        //第二方式
                        if (this.loginType == 'email') {
                            this.loginType = 'phone'
                        } else {
                            this.loginType = 'email'
                        }
                        return this.loginType;
                    }


                }

            })
        </script>
    </body>
</html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM