1. Regular Watch
Data () { return { frontpoints:0 }},watch: { frontpoints (newvalue, oldValue) { Console.log ( newvalue) }}
2, array of Watch
Data () { return { winchips:new Array (one). Fill (0) }},watch: {winchips: {
Handler (NewValue, OldValue) {
for (Let i = 0; i < newvalue.length; i++) {
if (oldvalue[i]! = Newvalue[i]) {
Console.log (NewValue)
}
}
},
Deep:true
}
}
3. Watch for objects
Data () {return {bet: {
Pokerstate:53,
Pokerhistory: ' Local '
} }},watch: {bet: {
Handler (NewValue, OldValue) {
Console.log (NewValue)
},
Deep:true
}
}
Tips: As long as the attributes in the bet change (can be monitored), the handler function will be executed;
If you want to monitor specific property changes, such as pokerhistory changes, to perform the handler function, you can use the computed attribute computed to do the middle tier.
Examples are as follows:
4, the object specific properties of the watch[utilization computed]
Data () {return {bet: {
Pokerstate:53,
Pokerhistory: ' Local '
} }},
Computed: {
Pokerhistory () {
Return this.bet.pokerHistory
}
},watch: {pokerhistory(newvalue, OldValue) {
Console.log (NewValue)
}
}
Vue combat problem-watch array or object