Objective
Vue.js is a data-driven Web interface library. Vue.js is focused only on the view layer and can be easily consolidated with other libraries. Only 24kb after code compression
Vue.js provides a way to watch observe data changes on a Vue instance. Corresponding to an object, the key is an observation expression, and the value is the corresponding callback. The value can also be a method name, or an object, containing an option.
Called for each key at instantiation time$watch() ;
<template>
//Observation data is a string or array
<input v-model= "Example0"/>
<input v-model= "example1"/>< c4/>/When the single observation data Examples2 as the object, if the key value changes, in order to monitor the data changes, need to add deep:true parameters
<input v-model= "Example2.inner0"/>
</template>
<script>
Export Default {
data () {return
{
Exampl E0: "",
example1: "",
example2:{
inner0:1,
innner1:2
}
}
,
watch:{
example0 (curval,oldval) {
Console.log (curval,oldval);
example1: ' A ',//value can be methods method name
example2:{
//Note: When the observed data is an object or an array, curval and oldval are equal, Because the two parameters point to the same data object
handler (curval,oldval) {
conosle.log (curval,oldval)
},
deep:true
}
,
methods:{
A (curval,oldval) {
con Osle.log (Curval,oldval)}}}
</script>
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, if you have questions you can message exchange.