【发布时间】:2020-09-02 16:12:42
【问题描述】:
我对 vue.js 比较陌生。我正在尝试创建一个初始显示状态设置为 false 的模式对话框。此对话框用于另一个组件,如波浪所示。
我无法弄清楚为什么 data 是 isOpen 是 undefined
// My main component here
<template>
<button @click="openMyModal">Open</button>
<MyDialog ref="dialog"/>
</template>
<script>
...
methods: {
openMyModal(){
this.$refs.dialog.open().then((confirm) => {
console.log("confirm", confirm)
return true
}).catch();
}
}
...
</script>
<template>
<div class="overlay" v-if="isOpen">
<div class="modal">
<h1>My modal dialog here</h1>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'my-dialog'
}
data () {
return {
isOpen: false
...
}
}
methods() {
open() {
this.isOpen = true;
...
},
close() {
this.isOpen = false;
},
}
</script>
【问题讨论】:
标签: vue.js modal-dialog vue-component