在组件页面定义好数据和方法,并把方法暴露出去
父组件中引入子组件,给子组件绑定ref属性。
在父组件需要的点击身上绑定事件,事件中写this.refs.init()调用子组件的方法弹出提示框
点击事件页面
<template>
<div>
<el-button @click="open()">添加</el-button>
<addOrUpdate ref="ts"/>
</div>
</template>
<script>
import addOrUpdate from './addOrUpdate.vue'
export default {
components:{
addOrUpdate
},
methods: {
open(){
this.$refs.ts.init()
}
}}
</script>
弹出层
<template>
<div>
<el-dialog
title="提示"
:visible.sync="dialogVisible"
width="30%"
:before-close="handleClose"
>
<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>
</div>
</template>
<script>
export default {
data() {
return {
dialogVisible: false,
};
},
methods: {
init(){
this.dialogVisible= true
}
},
};
</script>