[Vue.js] 切换登录方式

2018-10-29  本文已影响0人  大写K

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Vue - 我的学习</title>
    <script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
</head>

<body>
<div id="app">
    <template v-if="loginType === 'username'">
        <label>UserName</label>
        <input placeholder="Enter your username" key="username-input" />
    </template>
    <template v-else-if="loginType === 'email'">
        <label>Email</label>
        <input placeholder="Enter your email" key="email-input" />
    </template>
    <br />
    <button @click="switchLoginType">switch login type</button>
</div>
<script>
var vm = new Vue({
    el: "#app",
    data: {
        loginType: 'username'
    },
    methods: {
        switchLoginType: function () {
            console.log(this.loginType);
            this.loginType = (this.loginType == 'username') ? 'email' : 'username';
            return this.loginType;
        }
    }
})
</script>
</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读