Home > Web Front-end > JS Tutorial > Introduction to methods of Vue monitoring objects and methods of monitoring properties in objects (code)

Introduction to methods of Vue monitoring objects and methods of monitoring properties in objects (code)

不言
Release: 2018-08-20 14:10:07
Original
3076 people have browsed it

The content of this article is about the methods of Vue monitoring objects and the introduction (code) of the methods of monitoring the properties in the objects. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.

To monitor the entire object, just use watch

export default {
    data() {
        return {
            a: {
                b: 1,
                c: 2
            }
        }
    },
    watch() {
        a: {
            handler(newVal, oldVal) {
                console.log('监听a整个对象的变化');
            },
            deep: true
        }
    }
}
Copy after login

To monitor changes in specific properties of the object, you need to use watch with computed

export default {
    data() {
        return {
            a: {
                b: 1,
                c: 2
            }
        }
    },
    watch() {
        bChange() {
            console.log('监听a对象中b属性的变化');
        }
    },
    computed: {
        bChange() {
            return this.a.b;
        }
    }
}
Copy after login

Related recommendations:

Introduction to the properties and methods of basic JavaScript objects_Basic knowledge

Usage of Vue data monitoring method watch_vue.js

Use Vue.js to monitor property changes

The above is the detailed content of Introduction to methods of Vue monitoring objects and methods of monitoring properties in objects (code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template