0
点赞
收藏
分享

微信扫一扫

el-dialog父子组件传值问题

JamFF 2023-09-21 阅读 45

使用element -UI的el-dialog去做一个登陆弹窗的组件,需求是在登录完成后关闭弹窗

父组件代码

<template>
	<div v-if="isLogin==false" class="login-btn" @click="toLogin">登录</div>
	<Login :visible="dialogVisible" @close="closeDialog"></Login>
</template>
<script>
	 export default {
        name: "Mall",
        data() {
        	return {
        		dialogVisible: {flag:false},
        	}
        },
        methods: {
        	toLogin(){
                this.dialogVisible.flag = true;
            },
        	closeDialog(){
                this.dialogVisible.flag = false
            }
        }
     }
</script>

子组件代码

<template>
    <el-dialog :visible.sync='visible.flag' width="30%" :close-on-click-modal="false">
        <div class="login-warp">
            ...
        </div>
    </el-dialog>
</template>
<script>
    export default {
        name: "LoginDialog",
        props: ['visible'],
        methods:{
        	handleLogin() {
        		this.$store.dispatch("Login",this.loginForm).then(() => {
        				//当登录成功之后,调用父组件的close方法,改变dialogVisible对象的值
                            this.$emit('close')
                        }).catch(() => {
                            this.loading = false;
                            if (this.captchaOnOff) {
                                this.getCode();
                            }
                        });
        	}
        }
<script>
举报

相关推荐

0 条评论