vue弹出框组件

1.PopupPage.vue

<template>
  <div class="yh-popup-page" v-show="visible">
    <div class="yh-block">
      <div class="yh-headder">
        <span>{{title}}</span>
        <button @click="onClose" v-if="closable !== false" class="yh-icon">X</button>
      </div>
      <div class="yh-content">
        <slot></slot>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "PopupPage",
  data() {
    return {
      visible: false
    };
  },
  props: ["title", "closable"],
  methods: {
    onClose() {
      this.$emit("close", this);
    },
    close() {
      this.visible = false;
    },
    show() {
      this.visible = true;
    }
  }
};
</script>
<style scoped>
</style>

2.PopupPageDemo.vue

<template>
  <div class="yh-page">
    <h1>弹出框演示</h1>
    <div class="desc">Demo源代码:
      <code>/examples/components/modules/PopupPageDemo.vue</code>
    </div>
    <yh-button @click="showPopup">显示弹出框</yh-button>
    <yh-popup-page ref="popup" title="弹出框" @close="onClose">
      <div>
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="名称" prop="name">
            <el-input v-model="form.name" style="width:300px;" size="small"></el-input>
          </el-form-item>
          <el-form-item>
            <yh-button class="yh-primary" @click.prevent="submitForm">提交</yh-button>
            <yh-button>重置</yh-button>
          </el-form-item>
        </el-form>
      </div>
    </yh-popup-page>
  </div>
</template>
<script>
import yhbutton from "../comcompont/Button";
import popuppage from "../comcompont/PopupPage";
export default {
  name: "PopupPageDemo",
  data() {
    return {
      form: {
        name: ""
      }
    };
  },
  methods: {
    showPopup() {
      this.$refs.popup.show();
    },
    onClose(page) {
      page.close();
    },
    submitForm() {
      this.$refs.popup.close();
    }
  },
  components: {
    "yh-button": yhbutton,
    "yh-popup-page": popuppage
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scope>
</style>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值