Instead, use a data or computed property based on the prop's value. Vue JS

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 04:17:15

The warning is pretty clear. In your changeValue method you are changing the value of the property, menuOpen. This will change the value internally to the component, but if the parent component has to re-render for any reason, then whatever the value is inside the component will be overwritten with the current state outside the component.

Typically you handle this by making a copy of the value for internal use.

export default {
  name: 'layout',
  props: [ 'menuOpen' ],
  data(){
      return {
          isOpen: this.menuOpen
      }
  },
  methods: {
    changeValue: function () {
      this.isOpen= !this.isOpen
    }
  },
}

If you need to communicate the change of the value back to the parent, then you should $emit the change.

changeValue: function () {
    this.isOpen= !this.isOpen
    this.$emit('menu-open', this.isOpen)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!