对话框-封装组件的步骤

对话框-封装组件的步骤

效果图

在这里插入图片描述

第一步:在同层级或components文件夹下新建组件文件deployment.vue
<template>
  <div class="container">
    <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 {
  name: "deployment",
  data() {
    return {
      dialogVisible: false,
    };
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭?")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
  },
};
</script>
<style scoped lang="less">
</style>
第二步:在父组件进行注册、引入和调用

模块中,调用

 <Deployment ref="dialog2" />
     
<el-button
      @click="deploy()"
      type="primary"
      size="small"
      v-if="scope.row.code && scope.row.children"
      ><i class="el-icon-aim"></i>部署
</el-button>

引入

import Deployment from "./deployment";

 dialogVisible: false,   //默认值

注册和使用

 components: {
    Deployment,
  },
  methods: {
    deploy() {
      // console.log(this.$refs.dialog)
      this.$refs.dialog2.dialogVisible = !this.$refs.dialog2.dialogVisible;
    },
  },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值