vue watch prop Vue2.0用 watch 观察 prop 变化(不触发)

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

vue watch prop Vue2.0用 watch 观察 prop 变化(不触发)

akaylh   2021-03-29 我要评论
想了解Vue2.0用 watch 观察 prop 变化(不触发)的相关内容吗,akaylh在本文为您仔细讲解vue watch prop的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:vue,watch,prop,vue,watch,不触发,vue,触发watch,下面大家一起来学习吧。

本文介绍了Vue2.0用 watch 观察 prop 变化(不触发),分享给大家,具体如下:

A 组件:

export default {
 props:{
 name:{
 type:String
 }
 },
 data () {
 return {
  author: "Jinkey"
 }
 },
 mounted:function(){
 this.author = 'lili'
 },
 watch:{
 name:function(){
 console.log(this.name);
 },
 author:function(){
 console.log('lili');
 }
 }
}

author 有监测到变化,并输出了 lili ; name 由 B 组件传入,却没有监测到,控制台没有输出。

在 B 组件里调用 A 组件,并传值给 name

<firstcomponent :name="name"></firstcomponent>

import firstcomponent from './component/firstcomponent.vue'
export default {
 data () {
 return {
  msg: 'Hello Vue!',
  name:'lili'
 }
 },
 components: { firstcomponent}
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们