vue中watch侦听器

vuewatch侦听器

创建侦听器

  • 创建数据:msg

  • 添加监听器

    •   watch: {
          'msg': function (newValue, oldValue) {
            console.log(oldValue + '----' + newValue)
          }
        }
      
    • 参数一为变化后的新值

    • 参数二为变化前的旧值

  • <input type="text" v-model="msg">

  • 运行结果
    在这里插入图片描述

watch监听路由变化

  • 创建监听器

    • '$route.path': function (newValue, oldValue) {
      	console.log(oldValue + '----' + newValue)
      }
      
  • 运行结果
    在这里插入图片描述

发布了86 篇原创文章 · 获赞 45 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_25884515/article/details/104113620