vue v-if v-else用户登录案例

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <p>{{ message }}</p>
      <span v-if="ifUser">
        <label for="username">用户名:</label>
        <input type="text" id="username" value="" placeholder="用户名" />
      </span>
      <span v-else>
        <label for="email">邮箱:</label>
        <input type="text" id="email" value="" placeholder="邮箱" />
      </span>
      <button type="button" @click="ifUser = !ifUser">切换</button>
    </div>

    <script>
      const app = new Vue({
        el: '#app',
        data: {
          message: 'Hello Vue.js!',
          ifUser: true,
        },
      })
    </script>
  </body>
</html>

posted @ 2021-07-01 19:23  thomas_blog  阅读(165)  评论(0编辑  收藏  举报