ElementUI的Upload上传,配合七牛云储存图片

七牛云服务器的储存区域

存储区域

地域简称

上传域名

华东

z0

服务器端上传:http(s)://up.qiniup.com

华东

z0

客户端上传: http(s)://upload.qiniup.com

华北

z1

服务器端上传:http(s)://up-z1.qiniup.com

华北

z1

客户端上传: http(s)://upload-z1.qiniup.com

华南

z2

服务器端上传:http(s)://up-z2.qiniup.com

华南

z2

客户端上传: http(s)://upload-z2.qiniup.com

北美

na0

服务器端上传:http(s)://up-na0.qiniup.com

北美

na0

客户端上传: http(s)://upload-na0.qiniup.com

东南亚

as0

服务器端上传:http(s)://up-as0.qiniup.com

东南亚

as0

客户端上传: http(s)://upload-as0.qiniup.com

1<template> 2 <div class="container"> 3 <div class="title"><h2>ElementUI的Upload上传图片到七牛云</h2></div> 4 <el-upload 5 class="upload-demo" 6 drag 7 :action="upload_qiniu_url" 8 :show-file-list="false" 9 :on-success="handleAvatarSuccess" 10 :on-error="handleError" 11 :before-upload="beforeAvatarUpload" 12 :data="qiniuData"> 13 <img v-if="imageUrl" :src="imageUrl" class="avatar"> 14 <div v-else class="el-default"> 15 <i class="el-icon-upload"></i> 16 <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div> 17 </div> 18 <div class="el-upload__tip" slot="tip">只能上传jpg/png文件,且不超过2MB</div> 19 </el-upload> 20 </div> 21</template> 22 23<script> 24export default { 25 data() { 26 return { 27 qiniuData: { 28 key: "", 29 token: "" 30 }, 31 // 七牛云上传储存区域的上传域名(华东、华北、华南、北美、东南亚) 32 upload_qiniu_url: "http://upload-z1.qiniup.com", 33 // 七牛云返回储存图片的子域名 34 upload_qiniu_addr: "http://abc.clouddn.com/", 35 imageUrl: "", 36 Global: { 37 dataUrl: 'http://yoursite.com' 38 } 39 }; 40 }, 41 created() { 42 this.getQiniuToken(); 43 }, 44 methods: { 45 getQiniuToken: function() { 46 const _this = this; 47 this.$axios 48 .post(this.Global.dataUrl + "/qiniu/uploadToken") 49 .then(function(res) { 50 console.log(res); 51 if (res.data.success) { 52 _this.qiniuData.token = res.data.result; 53 } else { 54 _this.$message({ 55 message: res.data.info, 56 duration: 2000, 57 type: "warning" 58 }); 59 } 60 }); 61 }, 62 beforeAvatarUpload: function(file) { 63 this.qiniuData.key = file.name; 64 const isJPG = file.type === "image/jpeg"; 65 const isPNG = file.type === "image/png"; 66 const isLt2M = file.size / 1024 / 1024 < 2; 67 if (!isJPG && !isPNG) { 68 this.$message.error("图片只能是 JPG/PNG 格式!"); 69 return false; 70 } 71 if (!isLt2M) { 72 this.$message.error("图片大小不能超过 2MB!"); 73 return false; 74 } 75 }, 76 handleAvatarSuccess: function(res, file) { 77 this.imageUrl = this.upload_qiniu_addr + res.key; 78 console.log(this.imageUrl); 79 }, 80 handleError: function(res) { 81 this.$message({ 82 message: "上传失败", 83 duration: 2000, 84 type: "warning" 85 }); 86 } 87 } 88}; 89</script> 90 91<style scode> 92.title{ 93 margin:90px 0 40px 0; 94} 95.el-default .el-icon-upload { 96 margin-top: 125px; 97} 98.el-upload-dragger { 99 width: 350px; 100 height: 350px; 101} 102.avatar { 103 width: 350px; 104 height: 350px; 105 display: block; 106} 107</style>
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

Ueditor结合七牛云及百度云存储(JAVA版,ueditor

【前言】之前研究了ueditor直接上传图片文件到七牛云以及百度云存储,见下面两篇文章:http://uikoo9.com/blog/detail/ueditorforbcs(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F%2Fuikoo9.com%2Fblog%2Fdetail%

AWS国庆双重礼,仅限7天

自2021年10月1日00:00起至2021年10月7日24:00,新注册并激活(需全部完成账号注册的五个步骤,否则账号状态并未激活)AWS海外区域账户,填写页面下方表单,即可申领价值$200美元的AWS海外区域账户服务抵扣券直充到您的账户,用以抵扣服务消费,助您轻松体验多个云迁移应用场景。同时,您还可获赠AWS精美祥云纪念T恤一件。,仅限7天$20