# 弹窗 next-tick
<template>
<div class="demo-box">
<el-button @click="dlgVisible=true">打开弹窗</el-button>
<el-button @click="openWithData">打开弹窗(带数据)</el-button>
<el-dialog :visible.sync="dlgVisible" @open="handleOpen" @close="handleClose">
<form-builder ref="formBuilder" :form-data="formData" />
</el-dialog>
</div>
</template>
<script>
export default {
data() {
return {
dlgVisible: false,
formData: {
list: [{
type: 'input',
label: '名字',
model: 'name'
}]
}
}
},
methods: {
openWithData() {
this.dlgVisible = true
this.$nextTick(() => {
this.$refs.formBuilder.updateModel({
name: 'TyroCCC'
})
})
},
handleOpen() {
console.log(this.$refs.formBuilder) // 第一次打开时为 undefined
this.$nextTick(() => {
console.log(this.$refs.formBuilder) // VueComponent
})
},
handleClose() {
this.$refs.formBuilder.resetFields()
}
}
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46