当前位置: 首页 > news >正文

北京网站建设哪家好市场监督管理局官网

北京网站建设哪家好,市场监督管理局官网,网站建设的增值税税率,网站页面设计图是用什么软件画的需求&#xff1a;上面有几个按钮&#xff0c;其中有一个切换是图片 用v-if会导致图片加载慢 实现方法&#xff1a; 一进来就加载&#xff0c;通过监听元素显示&#xff0c;用于控制canvas的宽高&#xff0c;从而达到隐藏的效果 组件dowolad.vue <template><view …

需求:上面有几个按钮,其中有一个切换是图片

用v-if会导致图片加载慢

实现方法:

一进来就加载,通过监听元素显示,用于控制canvas的宽高,从而达到隐藏的效果

组件dowolad.vue

<template><view style="margin-top: 20rpx;"><canvas canvas-id="myCanvas" :style="scaleObj"></canvas><button :loading="loading" :disabled="loading" @click="saveImg" class="confirmBnt" v-if="!weixin && show">保存二维码</button></view></template><script>export default {props: ['show'],data() {return {show: true,canvasId: 'myCanvas',imagePath: '',canvaseAttr:{width: 0,height: 0,},scaleObj:{},loading: false,weixin: false};},mounted(){this.weixin = this.$wechat.isWeixin();this.init();},watch:{show:{handler(newData, oldData){let scale = {width: 0,height: 0,}if(newData){scale.width = this.canvaseAttr.width+'px';scale.height = this.canvaseAttr.height+'px';}this.scaleObj = scale;},deep: true,immediate: true}},methods: {init(){this.getImageInfo();},getImageInfo() {let that = this;uni.getSystemInfo({success: (window) => {const screenWidth = window.windowWidth;uni.getImageInfo({src: 'https://media.sammu.top/pay_bank_img.png',success: (res) => {let scale = screenWidth/res.width;let height = res.height*scale;that.canvaseAttr = {width: screenWidth,height: height,}that.imagePath = res.path;that.drawCanvas();},fail: (err) => {console.log(err);}});},});},drawCanvas() {this.$nextTick(()=>{const ctx = uni.createCanvasContext('myCanvas', this);ctx.drawImage(this.imagePath, 0, 0, this.canvaseAttr.width, this.canvaseAttr.height);ctx.draw();})},saveImg(){const ctx = uni.createCanvasContext(this.canvasId, this);let that = this;that.loading = true;// 绘制完成  ctx.draw(true, function () {uni.canvasToTempFilePath({canvasId: that.canvasId,success: (res) => {// #ifdef H5that.saveH5Canvas(res)// #endif// #ifdef APPuni.saveImageToPhotosAlbum({filePath: res.tempFilePath,success: () => {uni.showToast({title: '保存成功',icon: 'none'})that.loading = false;uni.hideLoading();},fail: () => {uni.showToast({title: '保存失败',icon: 'none'})that.loading = false;uni.hideLoading();}});// #endif},fail: (err) => {that.loading = false;console.log(err, "错误信息");}});})},saveH5Canvas(res) {let that = this;try {// 在 h5 中,res.tempFilePath 返回的是 base64 类型要处理,通过 a 标签的形式下载var arr = res.tempFilePath.split(',');var bytes = atob(arr[1]);let ab = new ArrayBuffer(bytes.length);let ia = new Uint8Array(ab);for (let i = 0; i < bytes.length; i++) {ia[i] = bytes.charCodeAt(i);}var blob = new Blob([ab], {type: 'application/octet-stream'});var url = URL.createObjectURL(blob);var a = document.createElement('a');a.href = url;a.download = new Date().valueOf() + ".png";var e = document.createEvent('MouseEvents');e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);a.dispatchEvent(e);URL.revokeObjectURL(url);uni.showToast({title: '保存成功',icon: 'none'})that.loading = false;uni.hideLoading();} catch (e) {uni.showToast({title: '保存失败',icon: 'none'})that.loading = false;uni.hideLoading();}    },},}</script><style lang="scss" scoped>.confirmBnt{position: fixed;bottom: 20rpx;width: calc(100% - 20rpx);left: 50%;transform: translateX(-50%);background: var(--view-theme);border-radius: 24rpx;height: 108rpx;line-height: 108rpx;font-size: 40rpx;font-weight: 700;text-align: center;color: #fff;}</style>

调用

<dowload ref="dowloadRef" :show="active == 1"></dowload>

http://www.hkea.cn/news/14130/

相关文章:

  • 网站系统与网站源码的关系网络流量分析工具
  • 企业网站模板网 凡建站搜索引擎优化的常用方法
  • 制作海报用什么软件天津seo网站管理
  • 专门做加盟的网站营销排名seo
  • 网上快速学做网站东莞网站建设制作
  • 网站建设如何做报价百度销售平台怎样联系
  • 聊城专业网站建设公司西安seo按天收费
  • 全球网购平台排名前十seo类目链接优化
  • 青岛网站建设保山seo怎么优化软件
  • 菜户营做网站宁波seo整体优化公司
  • python网站开发的毕业论文营销技巧第三季
  • 平泉建设局网站北京优化网站公司
  • 什么网站有做面条的app本地服务推广平台哪个好
  • 微信接口开发平台如何优化企业网站
  • 江苏网站备案要多久cilimao磁力猫在线搜索
  • 做app找哪个网站互联网营销师怎么考
  • 二级域名做网站域名app推广软文范文
  • 网站建设要域名和什么科目百度新闻最新消息
  • 河北保定网站建设发布软文广告
  • 企业网络营销分析报告江苏seo外包
  • 太湖县城乡建设局网站近三年成功的营销案例
  • 网站做压力测试 环境正规电商平台有哪些
  • 做咨询类网站风险评估5118站长工具箱
  • 做网站产品图片素材关键词优化公司哪家强
  • 青山做网站独立站建站平台
  • 网站排名优化平台seo优化价格
  • 广州视频网站建站公司长沙今日头条新闻
  • 犀牛云做网站编辑上传抖音视频排名优化
  • 深圳哪里有做网站的公司网页设计代码大全
  • 网站维护一年多少费免费域名解析