vue子组件修改父组件值时报错

报错

Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "type"

问题

目前有三个组件 A组件引用了B组件 B组件里面有个props B组件引用了C组件 现在这个C组件怎么改变那个B组件Prop的值呢?

解决

C组件中抛出事件 this.$emit("change","close");在changeStatus方法中修改type值

  <DialogBar :type="authType" :value="AuthFlag" @close="close" @confirm="confirm()" title="卡密码验证">
       <AuthComponent ref="AuthComponent"  @change="changeStatus"/>(C组件)
  </DialogBar>

不能直接修改父组件通过props传来的值,要抛出事件,让父组件自己修改,一层一层往上抛事件,那个值是谁提供的就让谁修改。

😆 😊 😃

posted @ 2019-12-10 16:05  Amy小影儿  阅读(474)  评论(0编辑  收藏  举报