11
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?