Vue combat problem-watch array or object

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.