gpt4 book ai didi

javascript - Vuetify 对话框设置从子项到父项的 prop 突变

转载 作者:行者123 更新时间:2023-12-04 13:41:24 26 4
gpt4 key购买 nike

我目前正在使用这个打开一个对话框组件

家长

<v-btn color="#EF5350" dark small absolute top right fab 
@click="showDialog">

<v-icon>zoom_in</v-icon>

</v-btn>

<UIDialog :dialog="dialog" @updateDialog="dialog = $event" />

<script>
import UIDialog from '@/components/UI/UIDialog';
export default {
data() {
return {
dialog: false
}
}
components: {
UIDialog
},
methods: {
showDialog() {
this.dialog = true;
}
}
}
</script>

这将打开对话框,因为我将对话框设置为 true
child
<v-dialog v-model="dialog" fullscreen scrollable>
<v-card>
This is a test
</v-card>
</v-dialog>

<script>
export default {
props: {
dialog: { type: Boolean, default: false }
},
watch: {
dialog(val) {
if (!val) this.$emit('updateDialog', false)
}
}
}
</script>

我使用 watch 因为 vue 对话框没有事件。我设法关闭了对话框,但我仍然收到
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

最佳答案

我设法通过使用计算属性来获取和设置对话框来解决我的问题

child

<v-dialog v-model="dialog" fullscreen scrollable>
<v-card>
This is a test
</v-card>
</v-dialog>

<script>
export default {
props: {
dialog: { type: Boolean, default: false }
},
computed: {
dialogState: {
get() {
return this.dialog;
},
set(val) {
this.$emit('updateDialog', false);
}
}
}
}
</script>

关于javascript - Vuetify 对话框设置从子项到父项的 prop 突变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56625851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com