Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
110
rated 0 times [  117] [ 7]  / answers: 1 / hits: 68621  / 9 Years ago, mon, january 11, 2016, 12:00:00

I have an element that I want to watch for a change like this:



<span id=slider-value-upper class=lower>50</span>


Is it possible to do this cleanly with vuejs? I tried looking in the docs but I could not find anything like this.



I want to launch a custom event whenever '50' changes to something else with VueJs.


More From » element

 Answers
23

Have you tried with watch?
In your case it would be something like this.



template



<div id=app>
{{ message }}
<span id=slider-value-upper class=lower>{{myValue}}</span><br />
<input v-model=myValue>
</div>


js code



new Vue({
el: '#app',
data: {
message: 'Watch example',
myValue: 50
},
watch: {
'myValue': function(val, oldVal){
if (val < 50) {
this.message= 'value too low!';
}else{
this.message= 'value is ok';
}
}
}
})


check out the example


[#63770] Friday, January 8, 2016, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
monetm

Total Points: 615
Total Questions: 103
Total Answers: 119

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
monetm questions
Fri, Feb 26, 21, 00:00, 3 Years ago
Wed, Sep 9, 20, 00:00, 4 Years ago
Sun, Jul 26, 20, 00:00, 4 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
;