0

I would like to be able to dynamically change the types,lables of an input field between text and email,number. how that possible ,i am new in vue js:

<input type="email">
2
  • Can you please explain the context? Why would you like to do this? What is the logic behind? Commented Mar 31, 2021 at 6:56
  • Possibly duplicated: stackoverflow.com/questions/44461188/… Commented Mar 31, 2021 at 6:58

2 Answers 2

2

First you need to declare this in your data:

data () {
  return {
    inputType: "text",
    lableName: "Default",
  }
}

Now you use these variables in your html:

<label>{{ lableName }}</label>
<input :type="inputType">

The last part is to define the logic when these values change. However, I don't know when or why you want to change this. If you elaborate I can edit.

Hope this helps already :)

Sign up to request clarification or add additional context in comments.

1 Comment

so i have an array in data function so i want to have for each index in array input with index name data () { return { data: { headers: [ 'Email', 'Name', 'DESC', 'Notes', 'reason' ] as yous see top this my data when i have a lable it should change like <lable> Email</label> ,<lable> Name</label>,<lable> DESC</label> @Wimancesir
1

You can use below syntax to make it dynamic For html:

<input :type="inputType">

In data:

data () {
  return {
    inputType: 'text'
  };
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.