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();
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球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 微信小程序 功能函数 购物车商品删除