vue Watch 监听 如何监听多个变量

1.在computed函数中 写一个方法 罗列需要监听的变量 并return

computed:{
            changeData(){
                const {phone,password,code,passwordFlag,Account} = this
                return{
                    phone,
                    password,
                    code,
                    Account,
                    passwordFlag
                }
            }
        },

  1. 在watch 周期函数中 精确监听
    watch:{
            /* 监听账号/密码/验证码 改变登陆按钮颜色 */
            changeData:{
                handler:function(n,o){
                    if(n.passwordFlag){
                        if(n.Account.length>0&&n.password.length>=6){
                            this.could=true  //控制登录开关
                        }
                    }
                    if(!n.passwordFlag){
                        if(n.Account.length>0&&n.code.length>=4){
                            this.could=true  //控制登录开关
                        }
                    }
                }
            }
        }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。