gb_spectrum
gb_spectrum

Reputation: 2301

vuejs - dynamic input 'types'

I would like to be able to dynamically change the type of an input field between text and password. I tried doing the following:

<input :type="dynamicInputType">

data() {
    return {
        dynamicInputType: 'password'
    }
}

But apparently this doesn't work; vuejs displays the error: v-model does not support dynamic input types. Use v-if branches instead.

It's not clear to me how I can fix this with v-if.

Upvotes: 3

Views: 1129

Answers (1)

Bert
Bert

Reputation: 82469

This kind of thing is what's being suggested.

<input v-if="'text' === dynamicInputType" type="text">
<input v-else type="password">

Upvotes: 3

Related Questions