Vue - Js Watch Property: Help Others, Please Share
Vue - Js Watch Property: Help Others, Please Share
Index.html file:
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vu
</script>
</head>
<body>
<div id = "wat_pro">
modelMeters
= "kilometers"><br/>
: <input type = "text" v-
model = "meters">
</div>
<script src="index.js"></script>
</body>
</html>
Index.js file:
el: '#wat_pro',
data: {
kilometers : 0,
meters:0
},
methods: {
},
computed :{
},
watch : {
kilometers:function(val) {
this.kilometers = val;
},
this.meters = val;
})
Index.css file:
html, body {
margin: 5px;
padding: 0;
Output:
You can see that the output has the 0 entry in its
textboxes. If you enter some values in the kilometers
textbox you can see the changes in the meters
textbox and vice-versa. Let's enter 50 in kilometers
textbox and see the result.
Output:
Output:
Example Explanation
Index.html file:
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vu
</script>
</head>
<body>
<script src="index.js"></script>
</body>
</html>
Index.js file:
el: '#eg_1',
data: {
firstName: 'Alex',
lastName: 'Panda',
},
watch: {
},
})
Output:
Index.html file:
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vu
</script>
</head>
<body>
<script src="index.js"></script>
</body>
</html>
Index.js file:
el: '#eg_2',
data: {
firstName: 'Alex',
lastName: 'Panda'
},
computed: {
fullName: function () {
})
Output:
You can see that both examples give the same result,
but the second one, "computer property" example is
much better and concise.
← prev next →
Solr MongoDB
Gimp Verilog
Teradata PhoneGap
Gmail Vue.js
PLC Illustrator
Postman
Preparation
Aptitude Reasoning
Verbal A. Interview
Company
Trending Technologies
AI AWS
Selenium Cloud
Hadoop ReactJS
D. Science Angular 7
Blockchain Git
ML DevOps
B.Tech / MCA
DBMS DS
DAA OS
C. Network Compiler D.
COA D. Math.
E. Hacking C. Graphics
C C++
Java .Net
Python Programs