gpt4 book ai didi

javascript - 关闭 `v-dialog` 时如何破坏食物成分?

转载 作者:行者123 更新时间:2023-12-05 00:39:28 29 4
gpt4 key购买 nike

我有 vuetify 应用程序,并在单击中打开一个对话框。在对话框中我有 Foo零件。

当我关闭对话框时,destroy Foo 上的事件组件不触发。

如何触发destoryFoo零件?我可以通过 vuetify 方式来做吗?

const Foo = {
template: `
<div>im fooo!!! <v-text-field :value="bar"></v-text-field></div>
`,
data () {
return {
bar: '',
}
},
mounted: function() {
console.log('mounted')
},
destroyed() {
console.log('destroyed');
}
}

new Vue({
el: '#app',
vuetify: new Vuetify(),
components: {
Foo
},
methods: {
open: function() {
this.dialog = true;
}
},
data () {
return {
dialog: false,
}
},
})
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vuetify@2.2.8/dist/vuetify.min.css">

<script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.2.8/dist/vuetify.min.js"></script>
<div id="app">
<v-app id="inspire">
<div class="text-center">
<v-dialog
v-model="dialog"
width="500"
>
<Foo />
</v-dialog>

<v-btn @click="open" color="red lighten-2" dark>
Click Me
</v-btn>
</div>
</v-app>
</div>

最佳答案

只需为组件添加 v-if ...

const Foo = {
template: `
<div>im fooo!!! <v-text-field :value="bar"></v-text-field></div>
`,
data () {
return {
bar: '',
}
},
mounted: function() {
console.log('mounted')
},
destroyed() {
console.log('destroyed');
}
}

new Vue({
el: '#app',
vuetify: new Vuetify(),
components: {
Foo
},
methods: {
open: function() {
this.dialog = true;
}
},
data () {
return {
dialog: false,
}
},
})
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vuetify@2.2.8/dist/vuetify.min.css">

<script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.2.8/dist/vuetify.min.js"></script>
<div id="app">
<v-app id="inspire">
<div class="text-center">
<v-dialog
v-model="dialog"
width="500"
>
<Foo v-if="dialog" />
</v-dialog>

<v-btn @click="open" color="red lighten-2" dark>
Click Me
</v-btn>
</div>
</v-app>
</div>

关于javascript - 关闭 `v-dialog` 时如何破坏食物成分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60004270/

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