Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vuejs - dynamic input 'types'

Tags:

vue.js

vuejs2

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.

like image 279
MonkeyOnARock Avatar asked Apr 10 '26 22:04

MonkeyOnARock


1 Answers

This kind of thing is what's being suggested.

<input v-if="'text' === dynamicInputType" type="text">
<input v-else type="password">
like image 184
Bert Avatar answered Apr 13 '26 23:04

Bert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!