LoginSignup
11
4

More than 3 years have passed since last update.

[Vue.js]パスワードの表示・非表示を切り替えるinput

Posted at

備忘録


デモ

onclick.gif

コード(JSFiddle)

解説

input内のアイコンに、
dataプロパティのフラグを切り替えるイベントを設定する。

<span :class="iconType" @click="onClick"></span>
methods: {
  onClick: function() {
    this.isChecked = !this.isChecked;
  }
}

inputのtypeを算出プロパティで切り替える。

 <input :type="inputType" id="password" class="input">
  computed: {
    inputType: function () {
      return this.isChecked ? "text" : "password";
    },
  }

もっとよいやり方をご存じの方がいたら教えてください。

11
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
4