首页 > 其他分享 >el-dialog 或dialog 封装 通过js控制

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

时间:2022-11-04 11:34:51浏览次数:52  
标签:el vue toastDom dialog seePicUrl fileReviewIndex 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();

 

标签:el,vue,toastDom,dialog,seePicUrl,fileReviewIndex,js
From: https://www.cnblogs.com/dianzan/p/16857171.html

相关文章

  • ArcGIS JS API 添加要素图层 点击时获取图层属性
    //需要引入:"esri/layers/FeatureLayer"模块//要素图层被点击时弹出图层属性的模板定义{为字段}varTuCeng03TC={"title":"ID:{objectid}",......
  • Vue、Three.js实现全景图
    一、首先我们需要创建一个Vue工程本文主要详细记录搭建全景图的过程,故搭建Vue工程不在过多描述。二、安装Three.jsnpminstallthree--savenpminstallthree-trackba......
  • JSON
    数据交换格式1、什么是数据交换格式数据交换格式,就是服务器端与客户端之间进行数据传输与交换的格式。前段领域,经常提及的两种数据交换格式分别是XML和JSON。其中......
  • django,models批量删除
    批量删除使用__intry:case_stepid=request.POST.get('case_stepid','')case_stepids=request.POST.get('case_stepids','')......
  • Selenium给元素的属性赋值
    我们在做UI自动化测试的过程中,某些情况会遇到,需要操作WebElement属性的情况。假设现在我们需要获取一个元素的title属性,我们可以先找到这个元素,然后利用get_attribute方法获......
  • js踩坑记录-数组
    数组比较eg1:以为打印出的是true,但是是false,原因是数组是引用数据类型,比较的时候比较的是地址,所以是不相等的。在C++中,数组也是不能通过这种方式比较的。但是python是可以......
  • Python yield 使用浅析
    之前了解了生成器的概念,带有yield的函数在Python中被称之为generator(生成器),那么应该什么时候使用呢?举个例子:简单输出斐波那契數列前N个数deffab(max):n,a,b=......
  • selenium-处理弹窗
    将以下代码copy至txt文本里,后缀改成html,然后用浏览器打开<html><head><title>Alert</title></head><body><inputid="alert"value=......
  • A01.shell脚本在子 shell和当前shell执行的区别
    简单测试脚本如下#!/bin/bashcd/homels执行顺序如子shell命令自行的方式:[root@pythonshell]#shsubshell.shwuziqicli[root@pythonshell]#bashsubshell.sh......
  • el-tree只展示前三个节点数据
    后端也返回了第四等级,但是不想让他展示,可以这样解决只展示前三等级//获取room树getRoomTreeList(){getRoomTree().then((res)=>{//只获取到......