封装vue插件(模拟element提示框)

执行代码

that.$confirm('确认导出选中记录吗?', '提示', {
        type: 'warning'
      })

预览效果
在这里插入图片描述
如果想要对按钮 “确定”进行操作,那是相当困难的;比如我希望给按钮‘确定’加上a标签,无解了感觉

后来只能自己封装一个 .vue弹出框插件

结构部分:

<template>
<div class="overall"  @click="remove">
  <div class="body_backgroud"></div>
  <div class="confirm">
    <div class="box">
      <div class="top">
        <span class="top_one">提示</span>
        <span class="top_two"  @click="remove">×</span>
      </div>
      <div class="content">
          <span class="content_one"><img src="/static/img/confirm.jpg" alt=""></span>
          <span class="content_two">确认导出选中记录吗?</span>
      </div>
      <div class="bottom">
          <span class="bottom_two button" @click="remove"><a class="testDom" :href="urlhttp">确定</a></span>
          <span class="bottom_one button" @click="remove">取消</span>
      </div>
    </div>
  </div>
</div>
</template>

行为部分:

<script>
import { CostMergeExcel } from '@/api/api'
export default {
  props: {
    confirmExport: Boolean,
    urlhttp: String,
  },
  data() {
    return {
    }
  },
  mounted() {
    console.log(this.urlhttp)
  },
  watch: {
    confirmExport() {
      this.getUrl()
    }
  },
  methods: {
    /* 获取url */
    getUrl () {
      // console.log(112)
      let that = this
      // let time = ''
      let para = this.queryOption()
      // console.log(para)
      that.startTime = para.begin_time.substr(0, 10)
      that.endTime = para.end_time.substr(0, 10)
      // let token = sessionStorage.getItem('token')
      // console.log(token)
      // time = that.startTime + '--' + that.endTime
      CostMergeExcel(para).then((res) => {
        // let blob = new Blob([res.data ], { type: 'application/octet-stream;charset=utf-8' }) // 创建一个blob对象
        // let a = document.getElementsByClassName('testDom')[0]
        // a.href = URL.createObjectURL(blob) // response is a blob
        // // console.log(a)
        // a.download = time + '.xlsx' // 文件名称
      })
    },
    remove () {
      let that = this
      document.getElementsByClassName('overall')[0].style.display = 'none'
      that.confirmExport = false
      this.$emit('closeConfirm', this.confirmExport)
    }
  }
}
</script>

样式部分:

<style scoped>
.overall{
  width: 100%;
  height: 100%;
  /* background: rgba(128, 128, 128, 0.7); */
  display: none;
  position: fixed;
  top: 0;
  left:0;
  z-index: 100;
}
.body_backgroud{
  width: 100%;
  height: 100%;
  background: rgba(128, 128, 128, 0.7);
  display: none;
  position: fixed;
  top: 0;
  left:0;
}
.confirm{
  width: 422px;
  height: 136px;
  background:#fff;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -moz-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  -o-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  border-radius: 10px;
}
.top{
  width: 100%;
  height: 52px;
  line-height: 52px;
}
.top_one{
  font-size: 20px;
  color:#00ad94;
  float: left;
  margin-left: 20px;
}
.top_two{
  font-size: 16px;
  color: #979aa0;
  float:right;
  margin-right: 20px;
  cursor: pointer;
}
.content{
  width: 100%;
  height: 25px;
  line-height: 25px;
}
.content img{
  display: inline-block;
  width: 25px;
  margin-left: 20px;
}
.content_two{
  font-size: 13px;
  color: #606266;
  margin-left: 10px;
}
.bottom{
  width: 100%;
}
.button{
  width: 56px;
  height: 32px;
  line-height: 32px;
  font-size: 12px;
  text-align: center;
  border:1px solid #dcdfe6;
  border-radius: 5px;
  margin-top: 15px;
  float: right;
  cursor: pointer;
}
.bottom_two{
   background: #32bda9;
   color: #fff;
   margin: 15px 15px 0 10px;
}
a{
  text-decoration:none;
  color: #fff;
}
</style>

效果:
在这里插入图片描述
按钮“确定”我是要这样子的

<span class="bottom_two button" @click="remove"><a class="testDom" :href="urlhttp">确定</a></span>

这样就解决了我的需求啦!!!!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值