代码:

<template>
<div class="upload-info">
<div>
<el-upload
class="upload-pic"
:action="domain"
:data="QiniuData"
:on-remove="handleRemove"
:on-error="uploadError"
:on-success="uploadSuccess"
:before-remove="beforeRemove"
:before-upload="beforeAvatarUpload"
:limit=""
multiple
:on-exceed="handleExceed"
:file-list="fileList"
>
<el-button size="small" type="primary">选择图片</el-button>
</el-upload>
<div>
<img class="pic-box" :src="uploadPicUrl" v-if="uploadPicUrl">
</div>
</div>
<div>
<el-button type="primary" :loading="loading" @click="handleSubmit">提交</el-button>
<el-button type="info" plain >取消</el-button>
</div>
</div>
</template> <script>
export default {
data() {
return {
loading: false,
QiniuData: {
key: "", //图片名字处理
token: "" //七牛云token
},
domain: "https://upload-z2.qiniup.com", // 七牛云的上传地址(华南区)
qiniuaddr: "http://xxxx.com", // 七牛云的图片外链地址
uploadPicUrl: "", //提交到后台图片地址
fileList: []
};
},
mounted() {
this.getQiniuToken();
},
methods: {
handleRemove(file, fileList) {
this.uploadPicUrl = "";
},
handleExceed(files, fileList) {
this.$message.warning(
`当前限制选择 张图片,如需更换,请删除上一张图片在重新选择!`
);
},
beforeAvatarUpload(file) {
const isPNG = file.type === "image/png";
const isJPEG = file.type === "image/jpeg";
const isJPG = file.type === "image/jpg";
const isLt2M = file.size / / < ; if (!isPNG && !isJPEG && !isJPG) {
this.$message.error("上传头像图片只能是 jpg、png、jpeg 格式!");
return false;
}
if (!isLt2M) {
this.$message.error("上传头像图片大小不能超过 2MB!");
return false;
}
this.QiniuData.key = `upload_pic_${file.name}`;
},
uploadSuccess(response, file, fileList) {
console.log(fileList);
this.uploadPicUrl = `${this.qiniuaddr}/${response.key}`;
},
uploadError(err, file, fileList) {
this.$message({
message: "上传出错,请重试!",
type: "error",
center: true
});
},
beforeRemove(file, fileList) {
// return this.$confirm(`确定移除 ${ file.name }?`);
},
//提交数据到后台
handleSubmit() {
let ajaxData = {
receipt_img: this.uploadPicUrl //图片地址
};
this.$http.put("/xxx", ajaxData)
.then(response => {
let { code, data } = response.data;
if (code == "") {
this.$message({
message: "提交成功!",
type: "success",
center: true
});
}
})
.catch(error => {
this.$message({
message: error.msg,
type: "error",
center: true
});
});
},
//请求后台拿七牛云token
getQiniuToken() {
this.$http.get("/xxx")
.then(response => {
let { code, data } = response.data;
if (code == "") {
this.QiniuData.token = data;
}
})
.catch(error => {});
}
}
};
</script>

vue图片上传到七牛云的更多相关文章

  1. 利用cropper插件裁剪本地图片,然后将裁剪过后的base64图片上传至七牛云空间

    现在做的项目需要做一些图片处理,由于时间赶急,之前我便没有处理图片,直接将图片放在input[type=file]里面,以文件的形式提交给后台,这样做简直就是最低级的做法,之后各种问题便出来了,人物头 ...

  2. KindEditor图片上传到七牛云

    自己做了一个网站,编辑器用的是KindEditor,平时会涉及到KindEditor自带的图片上传,但是服务器用的是虚拟主机,没多少空间,就一直想着把图片放在免费的云存储空间,之前看KindEdito ...

  3. django + ckeditor + 七牛云,图片上传到七牛云

    传送门 本人使用的是 Django 的自带的管理后台,安装 ckeditor 富文本编辑器后,上传图片的时候直接传到七牛云的.

  4. 图片上传到七牛云/阿里云的OSS

    1.准备 七牛云/阿里云OSS https://github.com/pfinal/storage 2.composer安装包 安装 composer require pfinal/storage 本 ...

  5. laravel7文件上传至七牛云并保存在本地图片

    HTML代码: <form class="layui-form" action="{{route('doctor.store')}}" method=&q ...

  6. 微信小程序文件上传至七牛云(laravel7)

    1 wxml: <view> <form bindsubmit="dopost"> <view> <label>真实姓名</l ...

  7. .Net Core实现将文件上传到七牛云存储

    功能:将图片上传到七牛云存储 准备工作 注册七牛账号,提交实名认证(基本上1天内内审核通过) 登录七牛后台->对象存储->新建空间 (基本概念:https://developer.qini ...

  8. 阿里云CentOS自动备份MySql 8.0并上传至七牛云

    本文主要介绍一下阿里云CentOS7下如何对MySql 8.0数据库进行自动备份,并使用.NET Core 将备份文件上传至七牛云存储上,并对整个过程所踩的坑加以记录. 环境.工具.准备工作 服务器: ...

  9. tp5 webupload文件上传至七牛云

    1:composer安装: composer require qiniu/php-sdk 2: 配置使用: 在tp5.1的配置文件app.php中配置七牛云的参数 'qiniu' => [ 'a ...

随机推荐

  1. 小E浅谈丨区块链治理真的是一个设计问题吗?

    在2018年6月28日Zcon0论坛上,“区块链治理”这个话题掀起了大神们对未来区块链治理和区块链发展的一系列的畅想. (从左至右,分别为:Valkenburgh,Zooko,Jill, Vitali ...

  2. Spring Boot系列(二) Spring Boot 之 REST

    Rest (Representational Stat Transer) 是一种软件架构风格. 基础理论 架构特性 性能 可伸缩 简化的统一接口 按需修改 组件通信透明 可移植 可靠性 架构约束 C/ ...

  3. pythonのdjango 信号

    一.内置信号 Django中提供了“信号调度”,用于在框架执行操作时解耦.通俗来讲,就是一些动作发生的时候,信号允许特定的发送者去提醒一些接受者. Model signals pre_init # d ...

  4. django+vue

    django安装配置方式略过 1.安装node.js,官网地址:https://nodejs.org/zh-cn/download/ 2.cd到项目目录下,执行npm install -g vue-c ...

  5. gitlab 随笔

    输入: $ git init $ git add . $ git commit -m 'init commit' 绿色部分为gitlab网页的项目创建后下面的ssh路径,也可以通过查看gitlab网页 ...

  6. Python爬虫基础之UrlError

    一.urllib.error python的urllib.error模块主要是应对urllib.request在网络请求过程中出现的异常而定义的异常处理类.主要有URLError和HTTPError两 ...

  7. 收藏一个可以学习javascript prototype的链接

    https://github.com/mqyqingfeng/Blog/issues/2

  8. C# 常用类型校验Validate

    using System.Text; using System.Text.RegularExpressions; namespace 落地页测试代码 { public class Validate { ...

  9. 关于javascript闭包(Closure)和return之间的暧昧关系

    什么是闭包?阮一峰老师说的很清楚了,定义在一个函数内部的函数,在本质上,闭包就是将函数内部和函数外部连接起来的一座桥梁. 首先要了解Javascript的变量作用域:全局变量和局部变量.全局嘛,就是共 ...

  10. oracle ORA-00119, ORA-00132问题解决

    使用PL/SQL登录oracle报ORA-12154: TNS: 无法解析指定的连接标识符sqlplus /nologconnect /as sysdbastartup报如下错误:ORA-00119: ...