源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-08-13 05:03 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Vue2.0用 watch 观察 prop 变化(不触发)
本文介绍了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}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部