Home > Blockchain >  using the v-modeled data in two variable in vue
using the v-modeled data in two variable in vue

Time:09-20

I v-model a data in my vue html to validate it in my form , but i also want to use it in other variable too this is my html

<input  : type="text"
            placeholder="title" :disabled="formIsSending" v-model="DataForValidating .categoryTitle">

this is my js code , but it does not work

 const DataForValidating = reactive({
      categoryTitle: '',
      categorySlug: '',
    })

 const categoryFormData = {
      categoryTitle: DataForValidating.categoryTitle,
      categorySlug: DataForValidating.categorySlug,
    }

i made categoryFormData reactive too , but it does not work

CodePudding user response:

i got answer , i need to use watcher

 watch:{
     'newCategoryData.categoryTitle': function (newVal){
      this.categoryFormData.categoryTitle=newVal
     },
     'newCategoryData.categorySlug': function (newVal){
      this.categoryFormData.categorySlug=newVal
     },
 }

CodePudding user response:

use @input event and pass a function then store "DataForValidating.categoryTitle" in another variable or you can directly use arrow function in @input event to assign that v-model variable to another

  • Related