0

That's where I change a value:

<div>
    <input type="text" id="global-tag1" v-model="liveTag1">
    <label for="global-tag1">label</label>
</div>

And I would like to update it everywhere here: Attention there are multiple of this pieces on my page. And I cannot do it with custom elements, I've done it and it worked but it takes to long to render the page.

 <div>
     <input name="someValue" value="{{$predefinedValue ?? ''}}" type="text" id="id1">
     <label for="id1">label</label>
 </div>

Now how do I achieve this with vue.js. Because I cannot simply set

value="{{liveTag1}}"

Then I do not have a predefined value.

2 Answers 2

1

Solution

var vm = new Vue({
    el: 'body',

    data: {
        liveTag1: ''
    }
});

This will observe the liveTag1 and as soon as the data changes it will update the value of the given Selector.

vm.$watch('liveTag1', function(value) {
    $('[id^="someid"]').val(value);
});
Sign up to request clarification or add additional context in comments.

Comments

0

Which version of Vue are you using? On current version you cannot do:

value="{{liveTag1}}"

for input fields, you need to do:

v-model="liveTag1"

Then if you want to set it to a predefined value, in your Vue instance:

Vue({
    data: {
        liveTag1: "something"
    }
})

1 Comment

thanks for your anwser, is not possible to predefine the value in the Vue instance, because it could be up to 1000 elements so I don't wanna write so much data attributes. I solved it with vm.$watch and used normal jquery to change the other values

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.