子组件传值父组件数据刷新的问题

12 篇文章 0 订阅

子组件监听值改变,自定义一个事件,在父组件使用时该事件为接收数据接口事件

子组件:监听open值的变化, 自定义事件  this.$emit("refreshPart")

watch: {
        open: {
            handler(val) {
                this.inputValue = val
                if (!val) {
                    this.contractSectId = ''
                    this.$emit("refreshPart")
                }
            }
        }
    },

父组件:接收事件 @refreshPart="getPartInfo"

<part-info ref="partinfo" @refreshPart="getPartInfo"></part-info>

父组件接口赋值事件 

getPartInfo() {
            this.partOptions = [];
            listPartialTree({
                teamId: this.form.teamId,
                projectId: this.form.projectId,
                contractSectId: this.form.contractSectId
            }).then(res => {
                this.partOptions = res.data;
            });
        },

子组件代码

<template>
    <el-dialog
        :title="title"
        :visible.sync="open"
        width="450px"
        append-to-body
    >
        <tree-select-edit
            :inputValue = "inputValue"
            :fatherId = "contractSectId"
        />
    </el-dialog>
</template>

<script>
import FormButton from '_c/FormButton'
import TreeSelectEdit from '_c/TreeSelectEdit/index'

export default {
    name: 'WorkMeteringApplyForm',
    components: {
        FormButton,
        TreeSelectEdit
    },
    data() {
        return {
            // 是否显示弹出层
            open: false,
            title: '工程部位',
            inputValue: false,
            contractSectId: undefined
        }
    },
    computed: {
        projectId() {
            return this.$store.getters.projectId
        }
    },
    watch: {
        open: {
            handler(val) {
                this.inputValue = val
                if (!val) {
                    this.contractSectId = ''
                    this.$emit("refreshPart");
                }
            }
        }
    },
    created() {
    },
    methods: {
        /** 打开对话框 */
        show(contractSectId) {
            this.open = true
            this.contractSectId = contractSectId
        }
    }
}
</script>

<style lang="scss" scoped>
    .el-col-form {
        height: 30px;
    }
    .list-div {
        margin-top: 20px;
        margin-bottom: 10px;
    }
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值