vue组件-props

props

只可读

sync

第一种方式:由于 props只具有可读性,不能在当前组件中修改props,要想实现组件中props数据的更新,需要使用this.$emit来更新父组件的数据,从而改变子组件的显示数据。

 <cardCustomRightsDialog :visible.sync="showDialog" v-bind.sync="myObject[0]">

子组件

 <el-input :value="crightName" size="small" @input="$emit('update:crightName',$event)"></el-input>

Data derived from prop

第二种方式是,父组件通过props往子组件传入数据,在子组件中进行拷贝一份,然后更新拷贝的值,再将该拷贝的对象返回给父组件,也就是产生一个新的对象。(也就是说data derived from prop

export default {
   
  props: {
   
    day_exr: {
   
      type: Object,
      required: true
    }
  },

  data: function () {
   
    return {
   
      id: this.day_exr.id,
      weight: this.day_exr.weight,
      auto_weight: Boolean(this.day_exr.auto_weight),
      auto_reps: Boolean(this.day_exr.auto_reps),
      day_id: this.day_exr.day_id,
      exercise_id: this.day_exr.exercise_id.toString(),
      increment: this.day_exr.increment,

上面这样写很乱 jsfiddle: 其中的一个灵感

编写组件

包邮组件

vue,父组件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值