vue-5 watch检测和深度检测

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>vue</title>
    </head>
    <body>
        <div id="app"></div>
        <script src="https://vuejs.org/js/vue.js"></script>
        <script>
            /*
                whtch监听


            */

            new Vue({
                el:"#app",
                template:`
                    <div>
                        输入:<input type="text" v-model='msg.text' /><br>
                        {{msg}}
                    </div>
                `,
                data:function(){
                    return {
                        msg:{text:''}
                    }
                },
                watch:{
                /*msg(newval,oldval){
                        if(newval=='love'){
                            alert(newval)
                        }
                    } */
                    msg:{
                        handler(newval,oldval){
                            if(newval.text=='love'){
                                alert(newval.text)
                            }
                        },
                        deep:true
                    }
                }


            })
        </script>
    </body>
</html>
发表评论 / Comment

用心评论~