vue子组件如何修改父组件data里的值

2021-05-24  本文已影响0人  NemoExpress

子组件修改父组件的值的时候报错
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.
按官方文档中的设计讲,父子组件中的数据流是单向的, 同时也给出了子组件操作数据时的解决方法.

// 父组件
....
<new-task :visible.sync="isTaskShow"></new-task>
....
// 子组件
....
 methods: {
    onClose() {
      this.$emit('update:visible', false)
    }
 }
...
上一篇 下一篇

猜你喜欢

热点阅读