I
I
Ivan Anikin2021-04-20 15:23:50
Vue.js
Ivan Anikin, 2021-04-20 15:23:50

How to change the input value of a vue.js component from another js?

There is a form on vue.js. There is a jqyery planin map on the page. It is necessary to substitute the addresses of selected points on the map in texarea.
I do it like this:

let $addres = $('#address');
if($addres.length){
   $addres.val("Мои данные").change();                
}

I even call the change event on texarea.
The data is substituted, but if you try to submit the form or make some changes to other fields, the substituted data is erased from this field. If you try to enter them manually, then everything is ok.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-04-20
@randomizex

$addres.val("Мои данные").change();

First - jquery and native events are not interchangeable. Of course, I don’t know about the first Vue.
Second, by default, Vue listens to the input event (change is if v-model is used with the lazy modifier).
So try replacing .change()with . [0].dispatchEvent(new Event('input'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question