element-ui 封裝dialog元件
阿新 • • 發佈:2018-12-01
<template> <div> <el-dialog title="title" :visible.sync="visible" @close="$emit('update:show', false)" :show="show"> <span>this is a dialog</span> </el-dialog> </div> </template> <script> export default { data () { return { visible: this.show }; }, props: { show: { type: Boolean, default: false } }, watch: { show () { this.visible = this.show; } } }; </script>
使用元件
<template>
<div>
<service-dialog :show.sync="show"></service-dialog>
<el-button @click="open">click</el-button>
</div>
</template>
<script>
import serviceDialog from './serviceDialog'
export default {
data () {
return {
show: false
};
},
methods: {
open () {
this.show = true;
}
},
components: {
serviceDialog
}
};
</script>