About Vue implemented method listener listens object

Vue can not hear the change in the object's internal attributes, internal objects familiar to listeners of changes, you must write:

<html>
    <head>
        <script src="https://vuejs.org/js/vue.js"></script>
    </head>
    <body>
        <div id="app">
            <ul>
                <li v-for="item in items" :key="item.id">
                    {{ item.name }}
                </li>
            </ul>
        </div>
        <script>
            var app = new Vue({
                el: '#app',
                data() {
                    return {
                        items:[
                            {
                                "id": 1,
                                "name": "twy"
                            },
                            {
                                "id": 2,
                                "name": "dw"
                            },
                            {
                                "id": 3,
                                "name": "lisa"
                            }
                        ]
                    }
                },
                methods: {
                    
                },
                watch: {
                    items:{
                        handler:function(k,v){
                            console.log("change!  ")
                        },
                        // immediate用于监测及时的改变
                        // immediate: true,
                        // 关键就是这句!,
                        deep:true,
                    }
                },
                computed: {
                    
                },
            })
        </script>
    </body>
</html>

Guess you like

Origin blog.csdn.net/weixin_33842304/article/details/90960517