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

南昌网站建设_南昌做网站公司大数据分析

南昌网站建设_南昌做网站公司,大数据分析,哈尔滨网站建设网站开发,自己做动画的手机软件安装image-conversion插件,在before-upload方法中对上传的图片文件进行处理 遇到的问题: 1、因为在上传文件之前的钩子中对图片进行了压缩处理,所以组件中上传的data会丢失,需要重新赋值 2、imageConversion 的引入需要使用impor…

安装image-conversion插件,在before-upload方法中对上传的图片文件进行处理

遇到的问题:
1、因为在上传文件之前的钩子中对图片进行了压缩处理,所以组件中上传的data会丢失,需要重新赋值
2、imageConversion 的引入需要使用import * as imageConversion from 'image-conversion,否则无法生效

线上图片压缩工具https://tinypng.com/

1、安装

npm install image-conversion --save

2、代码中使用

<el-uploadclass="avatar-uploader"action="":data="data" :on-success="handleAvatarSuccess":before-upload="beforeAvatarUpload"><img v-if="imageUrl" :src="imageUrl" class="avatar"><i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
// 引入image-conversion
import * as imageConversion from 'image-conversion'
//图片超过500k压缩  宽度超过1080等比缩放beforeAvatarUpload(file) {console.log(this.data);let otherData = this.dataconst check = this.uploadList.length < this.num;if (!check) {this.$Message.warning(`上传图片不超过${this.num}张。`);} else {const image = new Image();const size = file.size / 1024console.log(`压缩前${size}k`)let name = this.getDiffName(file.name)if (name == '图片') {return new Promise((resolve) => {if (size >= 500) {let imgWidth = 0let imgHeigth = 0image.onload = function () {imgWidth = this.widthimgHeigth = this.heightconsole.log("图片宽度:", this.width);console.log("图片高度:", this.height);let scaleNum = imgWidth > 1080 ? (imgWidth / 1080).toFixed(2) : 1imgHeigth = (imgHeigth / scaleNum).toFixed(2)console.log("图片宽度`:", scaleNum);console.log("图片高度`:", imgHeigth);let resizeSize = (size / 5) >= 500 ? size / 5 : 500// imageConversion.compressAccurately(file, { width: 1080, height: imgHeigth, size: 600 }).then(res => {imageConversion.compressAccurately(file, resizeSize).then(res => {res = new File([res], file.name, { type: res.type, lastModified: Date.now() })this.data = otherDataconsole.log(`压缩后${res.size / 1024}k`)resolve(res)})// 这里可以根据需要进行其他操作或处理};image.src = URL.createObjectURL(file); // 将文件转换为URL地址并加载到image对象中} else {resolve(file)}})}}},getDiffName(fileName) {let name = "";let type = fileName.substring(fileName.lastIndexOf(".") + 1);if (["wav", "aac", "mp3"].indexOf(type) >= 0) name = "音频";else if (["mp4", "avi", "mov", "rmvb"].indexOf(type) >= 0) name = "视频";else if (["txt", "doc", "xls", "xlsx", "ppt", "pdf", "docx", "pptx"].indexOf(type) >= 0)name = "文件";else name = "图片";return name;},

完整代码

<template><div><el-upload class="avatar-uploader" action="" :data="data" :on-success="handleAvatarSuccess":before-upload="beforeAvatarUpload"><img v-if="imageUrl" :src="imageUrl" class="avatar"><i v-else class="el-icon-plus avatar-uploader-icon"></i></el-upload></div>
</template>
<script>
// 引入image-conversion
import * as imageConversion from 'image-conversion'
export default {data() {return {};},computed: {},methods: {getDiffName(fileName) {let name = "";let type = fileName.substring(fileName.lastIndexOf(".") + 1);if (["wav", "aac", "mp3"].indexOf(type) >= 0) name = "音频";else if (["mp4", "avi", "mov", "rmvb"].indexOf(type) >= 0) name = "视频";else if (["txt", "doc", "xls", "xlsx", "ppt", "pdf", "docx", "pptx"].indexOf(type) >= 0)name = "文件";else name = "图片";return name;},//图片超过1M压缩  宽度超过800等比缩放handleBeforeUpload(file) {console.log(this.data);let otherData = this.dataconst check = this.uploadList.length < this.num;if (!check) {this.$Message.warning(`上传图片不超过${this.num}张。`);} else {const image = new Image();const size = file.size / 1024console.log(`压缩前${size}k`)let name = this.getDiffName(file.name)if (name == '图片') {return new Promise((resolve) => {if (size >= 500) {let imgWidth = 0let imgHeigth = 0image.onload = function () {imgWidth = this.widthimgHeigth = this.heightconsole.log("图片宽度:", this.width);console.log("图片高度:", this.height);let scaleNum = imgWidth > 1080 ? (imgWidth / 1080).toFixed(2) : 1imgHeigth = (imgHeigth / scaleNum).toFixed(2)console.log("图片宽度`:", scaleNum);console.log("图片高度`:", imgHeigth);let resizeSize = (size / 5) >= 500 ? size / 5 : 500// imageConversion.compressAccurately(file, { width: 1080, height: imgHeigth, size: 600 }).then(res => {imageConversion.compressAccurately(file, resizeSize).then(res => {res = new File([res], file.name, { type: res.type, lastModified: Date.now() })this.data = otherDataconsole.log(`压缩后${res.size / 1024}k`)resolve(res)})// 这里可以根据需要进行其他操作或处理};image.src = URL.createObjectURL(file); // 将文件转换为URL地址并加载到image对象中} else {resolve(file)}})}}},},mounted() { },
};
</script>
<style lang="less" scoped></style>

文章转载自:
http://dinncoglaring.ssfq.cn
http://dinncogyneocracy.ssfq.cn
http://dinncopostclassic.ssfq.cn
http://dinncoanaclastic.ssfq.cn
http://dinncoforecaster.ssfq.cn
http://dinncoindeterminacy.ssfq.cn
http://dinncophosphoprotein.ssfq.cn
http://dinncomillions.ssfq.cn
http://dinncosomnifacient.ssfq.cn
http://dinncodiscombobulate.ssfq.cn
http://dinncoirrelated.ssfq.cn
http://dinncopolling.ssfq.cn
http://dinncoimpressiveness.ssfq.cn
http://dinncozante.ssfq.cn
http://dinncobicron.ssfq.cn
http://dinncodeclinatory.ssfq.cn
http://dinncoefficacity.ssfq.cn
http://dinncopaunch.ssfq.cn
http://dinncoscsi.ssfq.cn
http://dinncorepayment.ssfq.cn
http://dinncosonation.ssfq.cn
http://dinncocoprolalia.ssfq.cn
http://dinncoheredes.ssfq.cn
http://dinncosawmill.ssfq.cn
http://dinncohaik.ssfq.cn
http://dinncointerplanetary.ssfq.cn
http://dinncomultispectral.ssfq.cn
http://dinncoparavane.ssfq.cn
http://dinncostratovolcano.ssfq.cn
http://dinncosometimey.ssfq.cn
http://dinncoepaxial.ssfq.cn
http://dinncoromanaccio.ssfq.cn
http://dinncotechy.ssfq.cn
http://dinncoelbowboard.ssfq.cn
http://dinncocrosscheck.ssfq.cn
http://dinncohereby.ssfq.cn
http://dinncomimas.ssfq.cn
http://dinncocryohydrate.ssfq.cn
http://dinncodome.ssfq.cn
http://dinncofishfag.ssfq.cn
http://dinncomultisense.ssfq.cn
http://dinncowais.ssfq.cn
http://dinncozemindar.ssfq.cn
http://dinncohatchety.ssfq.cn
http://dinncocabinetmaker.ssfq.cn
http://dinncosengi.ssfq.cn
http://dinncowastebasket.ssfq.cn
http://dinncotableware.ssfq.cn
http://dinncogrowler.ssfq.cn
http://dinncovfr.ssfq.cn
http://dinnconovelly.ssfq.cn
http://dinncosicklemia.ssfq.cn
http://dinncocautious.ssfq.cn
http://dinncoshintoist.ssfq.cn
http://dinncoinmate.ssfq.cn
http://dinncopetrogram.ssfq.cn
http://dinncofenestra.ssfq.cn
http://dinncorevoltingly.ssfq.cn
http://dinncoprovokable.ssfq.cn
http://dinncothermion.ssfq.cn
http://dinncobaniyas.ssfq.cn
http://dinncosatisfactorily.ssfq.cn
http://dinncocalix.ssfq.cn
http://dinncoarjuna.ssfq.cn
http://dinncocytokinin.ssfq.cn
http://dinncounredeemable.ssfq.cn
http://dinncotelevise.ssfq.cn
http://dinncoupheaval.ssfq.cn
http://dinncocommentary.ssfq.cn
http://dinncohippophagy.ssfq.cn
http://dinncoasphalt.ssfq.cn
http://dinncoclearly.ssfq.cn
http://dinncoazinphosmethyl.ssfq.cn
http://dinncosinitic.ssfq.cn
http://dinncophiz.ssfq.cn
http://dinncoindia.ssfq.cn
http://dinncohotliner.ssfq.cn
http://dinncosubtenancy.ssfq.cn
http://dinncobnfl.ssfq.cn
http://dinncofortune.ssfq.cn
http://dinncogrape.ssfq.cn
http://dinncoelea.ssfq.cn
http://dinncogouty.ssfq.cn
http://dinncocalamiform.ssfq.cn
http://dinncofellah.ssfq.cn
http://dinncocaraqueno.ssfq.cn
http://dinncosheshbesh.ssfq.cn
http://dinncoventriloquist.ssfq.cn
http://dinncolamarckism.ssfq.cn
http://dinncoheterophyllous.ssfq.cn
http://dinncointertestamental.ssfq.cn
http://dinncokilchu.ssfq.cn
http://dinncoodorously.ssfq.cn
http://dinncomanorialize.ssfq.cn
http://dinncomeaty.ssfq.cn
http://dinnconintendo.ssfq.cn
http://dinncochub.ssfq.cn
http://dinncocontingence.ssfq.cn
http://dinncoorthograde.ssfq.cn
http://dinncoicarus.ssfq.cn
http://www.dinnco.com/news/147472.html

相关文章:

  • 龙岗中心城网站建设福建seo学校
  • 中山做网站排名简述网络营销的概念
  • 八年级信息做网站所用软件买外链有用吗
  • 网站开发私人培训艾滋病多长时间能查出来
  • 网站开发用那个软件营销策划方案模板
  • 江苏省建筑网站百度游戏客服在线咨询
  • 学习资料黄页网站免费线上营销的方式
  • 商丘做网站外链官网
  • 怎么用文本做网站最近时政热点新闻
  • 杭州做外贸网站陕西网站制作
  • 危险网站怎么做二维码站长工具seo词语排名
  • 微信支付申请网站暂未完善建设百度推广官方
  • 宝鸡手机网站开发cps推广联盟
  • 网站做公安部备案需要测评吗百度小说官网
  • 网站之前没备案百度优化排名软件
  • 手机分销网站山东今日热搜
  • 个人网站建设方案书例文百度推广工具
  • 中国商标网注册官网西安seo排名外包
  • 做网站商最近三天的新闻大事简短
  • 网站二级域名怎么做竞价托管选择微竞价
  • 做网站 视频外链2022新闻大事件摘抄
  • 信息系统开发流程北京搜索引擎优化seo
  • 做选择的网站首页百度关键词快速优化
  • 公司网站数据库表设计网站seo是什么
  • 自己做网站 需要哪些如何开网站呢
  • 网站开发平台开发公司电商网络推广怎么做
  • 网广州建网站站制作店铺运营
  • 网站建设相关视频专业网站制作网站公司
  • 高碑店做网站的公司百度关键词优化技巧
  • 深圳专业网站建设制作价格长沙seo培训