el-dialog 或dialog 封装 通过js控制

1.通用组件封装dialogImg.vue

复制代码
<template>
  <div>
    <el-dialog
      v-show="isShow"
      :visible.sync="isShow"
      width="50%"
      @close="seePicUrl = ''"
      append-to-body
      style="text-align: center"
    >
      <img :src="seePicUrl" alt="" class="w" />
    </el-dialog>
  </div>
</template>
<script>

export default {
  name: 'dialogImg',
  data () {
    return {};
  },
  created () { },
  activated () { },
  methods: {
    closeFn () {
      this.$cancelSeePdf();
    },
  },
};
</script>
<style lang="scss" scope>
</style>
复制代码

2.吊起方法封装utils / fileReviewIndex.js

复制代码
import vue from 'vue'
import dialogImgComponent from '../components/dialog/dialogImg.vue'

const DialogImgConstructor = vue.extend(dialogImgComponent)

let toastDom, el;

function showDialogImg(seePicUrl) {

    if (!el && !toastDom) {
        el = document.createElement('div');
        toastDom = new DialogImgConstructor({
            el,
            data() {
                return {
                    isShow: true, // 是否显示
                    seePicUrl: seePicUrl
                };
            }
        });
        // 添加节点
        document.body.appendChild(toastDom.$el);
    } else {
        toastDom.seePicUrl = seePicUrl
        toastDom.isShow = true;
    }
}

function cancelDialogImg() {
    if (toastDom) {
        toastDom.isShow = false;
    }
}

// 全局注册
function registryToast() {
    vue.prototype.$showDialogImg = showDialogImg;
    vue.prototype.$cancelDialogImg = cancelDialogImg;
}

export default registryToast;
复制代码

3.main.js文件注册挂载

import fileReviewIndex from "./utils/fileReviewIndex";
Vue.use(fileReviewIndex);

4.吊起实例

this.$showDialogImg( window.URL.createObjectURL(new Blob([blob])))

5.关闭实例

 this.$cancelSeePdf();

 

posted @   ThisCall  阅读(678)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
历史上的今天:
2019-11-04 后台合成图片
2019-11-04 阿里云服务器添加nginx
2019-11-04 小程序时时聊天
2019-11-04 微信小程序裁剪
2017-11-04 微信小程序 功能函数 将对象的键添加到数组 (函数深入)
2017-11-04 微信小程序 功能函数 点击传参和页面
2017-11-04 微信小程序 功能函数 购物车商品删除
点击右上角即可分享
微信分享提示