Vue subcomponent and parent component colleagues need to modify the value defined in props will report an error?

three different messages need to be displayed in the subcomponents

<div v-if="one"><span></span></div>
<div v-if="two"><span></span></div>
<div v-if="three"><span></span></div>

defined in subcomponents

 props: {
    one: {
      type: Boolean,
      default: false
    },
    two:{
      type: Boolean,
      default: false
    },
    three:{
      type: Boolean,
      default: true
    }
  }

the parent component selects which piece of data to display when it needs to be opened, so there is no problem with using the above operation
but after clicking on the click event defined in the following span in the child component, switching between these three pieces of data will report an error, although it does not affect the use of

.
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: "one"
found in

can I define a function pass if I can"t have a single item?

  typeshow{
      validator: function (value) {
        if(value==="yi"){
          this.oneshow();
        }
        else if(value==="er"){
          this.twoshow();
        }
      }
    }
   }

I wonder if this will work. How to use it in the parent component?

Sep.16,2021

< H2 >-sharp 2 methods < / H2 >

first:

// 
<dialog-apply :visible.sync="dialogApplyVisible" />

// 
<el-dialog
      :visible.sync="visible"
      title=""
      :before-close="onClose"
>

onClose() {
  this.$emit('update:visible', false)
}

second:

// 
<dialog-apply :visible.sync="dialogApplyVisible" @close='dialogApplyVisible = false' />

// 
<el-dialog
      :visible.sync="visible"
      title=""
      :before-close="onClose"
>

onClose() {
  this.$emit('close')
}
< hr >

these two methods, : before-close is the key;


vue follows the one-way data flow principle, that is, no child components are proposed to change the data obtained from the parent component through props. So, if you change the one,two,three in the subcomponents here, you will report an error.
ide/components-props.html-sharp%E5%8D%95%E5%90%91%E6%95%B0%E6%8D%AE%E6%B5%81" rel=" nofollow noreferrer "> official document vue prop one-way data flow


this.oneshow (); there will be an error and cannot find the prompt undefined

Menu