1. 在父组件唤起子组件的dialog
//子组件dialog
<el-dialog
title="子组件dialog"
:visible.sync="dialogVisible"
width="30%"
<span>这是一段信息</span>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="dialogVisible = false">确 定</el-button>
</span>
</el-dialog>
<script>
export default {
data() {
return {
dialogVisible: false
};
},
methods: {
//打开dialog
openDialog() {
this.dialogVisible= true
}
}
}
</script>
//父组件
//触发打开子组件dialog的按钮
<el-button @click="addMaterial">打开子组件的dialog</el-button>
//子组件
<selMaterial ref="refMater"></selMaterial>
//引入
import selMaterial from './selMaterial'
//注册
components: {
selMaterial
}
//方法
addMaterial() {
this.$nextTick(() => {
this.$refs.refMater.openDialog()
})
}
利用$refs访问组件实例,父组件调用子组件的方法,打开dialog
2. 清空upload已上传的列表
通过$refs访问组件实例
<el-upload ref="uploadList"></el-upload>
//可以在方法中调用,比如关闭dialog的时候,清空列表,下次打开,列表为空
this.$refs.uploadList.clearFiles()
后续继续补充