Vue Element-UI dialog as a child component, how to control the display and hiding of dialog in the parent component?

Xiaobai, may I ask you a question:

subcomponents

<template>
  <el-dialog title="" :visible.sync="dialogTableVisiblee" @close="close">
    <el-table :data="gridData">
      <el-table-column property="date" label="" width="150"></el-table-column>
      <el-table-column property="name" label="" width="200"></el-table-column>
      <el-table-column property="address" label=""></el-table-column>
    </el-table>
  </el-dialog>
</template>
<script>
export default {
  props: {
    dialogTableVisiblee: Boolean
  },
  data () {
    return {
      gridData: [{
        date: "2016-05-02",
        name: "",
        address: " 1518 "
      }]
    }
  },
  methods: {
    close () {
      this.$emit("dialogHide")
    }
  }
}
</script>

parent component

<template>
  <div class="wrap">
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="name"
        label="">
      </el-table-column>
      <el-table-column
        fixed="right"
        label=""
        width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <modal @dialogHide="dialogHanderHide" :dialogTableVisiblee="isShow"></modal>
  </div>
</template>
<script>
import modal from "./modal"
export default {
  data () {
    return {
      tableData: [{
        date: "2016-05-02",
        name: "",
        member: 1,
        invited: 77,
        id: 789,
        address: " 1518 "
      },],
      isShow: false
    }
  },
  components: {
    modal
  },
  methods: {
    handleClick (row) {
      this.isShow = true
      // console.log(row)
    },
    dialogHanderHide () {
      this.isShow = false
    }
  }
}
</script>

Click to view can achieve the effect, but report an error

[Vue warn]: 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: "dialogTableVisiblee"

found in

---> <Modal> at src\components\modal.vue
       <Index> at src\components\index.vue
         <App> at src\App.vue
           <Root>
Mar.01,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;


sets a state with vuex, and the pop-up box shows or hides


add a model tag in your parent component to receive the data passed by the child component @ CB-dialog= "CB_dialog". In the method, change your dialogTableVisiblee to the false, child component and use the this.$emit ('CB-dialog',false) to pass the value to the parent component. And your sub-component props picture description: ['dialogTableVisiblee'], listen for changes in watch, do not bind the values assigned to your sub-component page, it will interfere with




Menu