Take a look at the main component:
<template lang="pug">
.wrapper
el-button(type="primary", @click="dialogAddUser = true") New User
hr
// Dialog: Add User
add-edit-user(:dialog-visible.sync="dialogAddUser")
</template>
<script>
import * as data from '@/components/partials/data'
import AddUser from './partials/AddUser'
export default {
name: 'users',
components: { AddUser },
data () {
return {
users: data.users,
dialogAddUser: false
}
}
}
</script>
And now, let's dive into the child component:
<template lang="pug">
el-dialog(width="75%", title="New User", :visible.sync="dialogVisible", top="5vh")
div 'el-dialog-body' - content goes here
</template>
<script>
export default {
name: 'add-user',
props: {
dialogVisible: Boolean
}
}
</script>
Opening the dialog
works fine, but when trying to close it using the top right button inside the dialog
, an error occurs:
Avoid directly mutating a prop as its value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. The prop being mutated is "dialogVisible"
I attempted to troubleshoot by making changes like so, but unfortunately, I am now unable to open the dialog
at all:
<template lang="pug">
el-dialog(width="75%", title="New User", :visible.sync="visibleSync", top="5vh")
div 'el-dialog-body' - content goes here
</template>
<script>
export default {
name: 'add-user',
props: {
dialogVisible: Boolean
},
watch: {
visibleSync (val) {
this.$emit('update:dialogVisible', val)
}
},
data () {
return {
visibleSync: this.dialogVisible
}
}
}
</script>