fe-interview icon indicating copy to clipboard operation
fe-interview copied to clipboard

[vue] 怎么在watch监听开始之后立即被调用?

Open haizhilin2013 opened this issue 7 years ago • 4 comments

[vue] 怎么在watch监听开始之后立即被调用?

haizhilin2013 avatar Jun 16 '19 14:06 haizhilin2013

有个参数immediate https://cn.vuejs.org/v2/api/#vm-watch

wenyejie avatar Jun 17 '19 01:06 wenyejie

  let vm=new Vue({
        el:"#first",
        data:{msg:'liuneng'},
        watch:{

            msg:{
                handler (newMsg,oldMsg){
                    console.log(newMsg);
                },
                immediate:true
            }
        }
    })

设置immediate属性为true

lancelote-zpc avatar Mar 18 '20 06:03 lancelote-zpc

选项:immediate

在选项参数中指定 immediate: true 将立即以表达式的当前值触发回调

crush2020 avatar Feb 02 '21 01:02 crush2020

直接添加watch.监听对象.immediate = true就ok

yxllovewq avatar Mar 09 '22 08:03 yxllovewq