element ui dialog 父子组件传值
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
·
最近在做课设的时候 用到了Elementui 中的dialog的组件,但在将dialog作为一个子组件的时候,传值出现了问题。当关闭dialog的时候应该怎么传值?
一开始的时候的想法比较简单,就是父组件直接传值来作为子组件的show/hidden的值。
然而这样的问题是当子组件close的时候,他会直接直接改变他的值,但是子组件不能直接改变props的值,因此可以通过子组件触发事件给父组件。
子组件在关闭时候的事件,通过阅读官方文档,我们发现他提供了一个关闭的时候的回调事件。

我们可以通过@close=“相应事件”来写需要给子组件传的事件。
父组件:
<el-button style="float: right; padding: 3px 8px" type="text" @click="report(item)">举报</el-button>
<accuse :accuseitem="accuseitem" :accuseVisible="accuseVisible" @close-dialogStatus="Close_dialog"></accuse>
data () {
return {
accuseitem: {},
accuseVisible: false
}
methods: {
Close_dialog (val) {
this.accuseVisible = false
},
report (item) {
this.accuseitem = item
this.accuseVisible = true
}
}
子组件:
<el-dialog
custom-class="m-dialog"
:visible.sync="vis"
width="100%"
top="0px"
@close="closeDialog"
:show-close="true"
>
</el-dialog>
props: {
accuseVisible: Boolean,
accuseitem: Object
},
watch: {
accuseVisible (newValue, oldValue) {
this.vis = newValue
}
},
data () {
return {
vis: false
}
}
methods: {
closeDialog () {
this.$emit('close-dialogStatus', true)
}
}
实现结果:

A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:2 个月前 )
c345bb45
1 年前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 1 年前
新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。
更多推荐

所有评论(0)