vue项目中使用element ui上传图片到七牛
1.获取token值
后台有接口调用直接返回token值
//请求后台拿七牛云token
async getQiniuToken() { //token
let uploadtoken = await
this.Fetch("/osg/resource/uploadtoken/image", {
method: "get",
});
console.log(uploadtoken);
//赋值保存在本地
this.QiniuData.token= uploadtoken.data.token
},
2.贴上页面代码
<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="3"
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
data:{}
},
domain: "http://upload.qiniup.com", // 七牛云的上传地址(华东区)
qiniuaddr: "http://image.********.cn", // 七牛云的图片外链地址 七牛云空间的外链地址
uploadPicUrl: "", //提交到后台图片地址
fileList: []
};
},
mounted() {
this.getQiniuToken();
},
methods: {
handleRemove(file, fileList) {
this.uploadPicUrl = "";
},
handleExceed(files, fileList) {
this.$message.warning(
`当前限制选择 3 张图片,如需更换,请删除上一张图片在重新选择!`
);
},
beforeAvatarUpload(file) { //图片上传之前的方法
// const isPNG = file.type === "image/png";
// const isJPEG = file.type === "image/jpeg";
// const isJPG = file.type === "image/jpg";
// const isLt2M = file.size / 1024 / 1024 < 2; // if (!isPNG && !isJPEG && !isJPG) {
// this.$message.error("上传头像图片只能是 jpg、png、jpeg 格式!");
// return false;
// }
// if (!isLt2M) {
// this.$message.error("上传头像图片大小不能超过 2MB!");
// return false;
// }
this.QiniuData.data = file;
this.QiniuData.key = `${file.name}`;
console.log(this.QiniuData.key)
},
uploadSuccess(response, file, fileList) { //图片上传成功的方法
console.log(fileList);
console.log(response);
console.log(file);
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() { },
//请求后台拿七牛云token
async getQiniuToken() { //token
let uploadtoken = await this.Fetch("/osg/resource/uploadtoken/image", {
method: "get",
});
console.log(uploadtoken);
this.QiniuData.token= uploadtoken.data.token
},
}
};
</script>
3.起初也是毫无头绪,看文档,看博客,如有雷同,纯属借鉴!
vue项目中使用element ui上传图片到七牛的更多相关文章
- 在Vue项目中使用Element UI:按需引入和完整引入
下面操作在main.js文件中进行 完整引入: import Element from 'element-ui'; //样式文件,需单独引入 import 'element-ui/lib/theme- ...
- php项目中使用element.ui和vue
1.plugins中添加axios,element-ui 2.全局文件下引入 <script src="/static/plugins/vue@2.5.13/vue.js"& ...
- 如何在Vue项目中使用Element组件
[前提] 1.安装webpack cnpm install webpack -g 2.安装vue/vue-cli cnpm install vue vue-cli -g 3.初始化vue ...
- vue项目中使用element的dialog中引入ztree却不能初始化解决办法
一开始我在 里边写的,发现获取不到,那么采用dialog自带的回调函数,窗口打开后opend进行处理, 结果:
- vue入坑教程(二)在vue项目中如何导入element以及sass
在项目中导入element以及sass.stylus等方便开发的工具以及UI框架 (1)如何在vue项目中导入elementUI框架 elementUI是饿了么团队开发出来基于vue的前端UI框架,其 ...
- 在vue项目中使用canvas-nest.js,报parameter 1 is not of type 'Element'
canvas-nest.js是一款轻量的网页特效,如图: github地址:https://github.com/hustcc/canvas-nest.js 在普通的html项目中,只要将<sc ...
- vue 项目中实用的小技巧
# 在Vue 项目中引入Bootstrap 有时在vue项目中会根据需求引入Bootstrap,而Bootstrap又是依赖于jQuery的,在使用npm按照时,可能会出现一系列的错误 1.安装jQu ...
- Vue项目中如何使用Element-UI以及如何使用sass
Vue项目中如何使用Element-UI以及如何使用sass 当我们在开发Vue项目的时候通常会选择Element-UI作为我们的UI框架,其官方中文文档地址是http://element.eleme ...
- Vue项目的创建和UI资源
Vue项目创建打包与UI资源 1.Vue项目创建 1.1 vue-cli脚手架 vue-cli是一个基于vue的构建工具,用于搭建vue项目的环境,有着兼容,方便,快速的优点,能够完全遵循前后端分离的 ...
随机推荐
- linux入门系列12--磁盘管理之分区、格式化与挂载
前面系列文章讲解了VI编辑器.常用命令.防火墙及网络服务管理,本篇将讲解磁盘管理相关知识. 本文将会介绍大量的Linux命令,其中有一部分在"linux入门系列5--新手必会的linux命令 ...
- windows本地安装以及使用Jenkins
首先保证本地已安装JDK,Jenkins是需要Java开发的,需要JDK运行环境,此处不提供,网上一大把. 一.Jenkin安装: 下载Jekins,到官网下载,https://jenkins.io/ ...
- Shell脚本 server rsync 控制脚本
[root@backup ~]# vim /etc/init.d/rsync#!/bin/bash #this script for start|stop rsync daemon service s ...
- 普通台式机装centos7系统
一.环境 台式机配置如下: 配置:CPU -i5-7400 内存:8G 硬盘:1T 原装系统: win7 64x 使用软碟通刻录U盘做系统启动盘,教程: 教你用UltraISO+U盘制作启动盘和安装各 ...
- 解决.net core3.1使用docker部署在Ubuntu上连接sqlserver报error:35的问题
最近把一个项目从core2.2迁移至core3.1,在本地win上跑没有问题,但是上线到生产Ubuntu docker环境下连接不上sqlserver报以下错误. A connection was s ...
- cesium1.63.1api版本贴地贴模型量算工具效果(附源码下载)
前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材.不少 ...
- MySQL必知必会--分 组 数 据
数据分组 目前为止的所有计算都是在表的所有数据或匹配特定的 WHERE 子句的 数据上进行的.提示一下,下面的例子返回供应商 1003 提供的产品数目 但如果要返回每个供应商提供的产品数目怎么办?或者 ...
- .net 用反射获取当前运行的程序集中的所有Controller与Action
public string InitPermission() { // 通过反射加载程序集 // var baseType = Assembly.LoadFile(@"G:\testproj ...
- hive中parquet存储格式数据类型timestamp的问题
当存储格式为parquet 且 字段类型为 timestamp 且 数据用hive执行sql写入. 这样的字段在使用impala读取时会少8小时.建议存储为sequence格式或者将字段类型设置为st ...
- Hibernate(六)--缓存策略
缓存: 缓存就是数据库数据在内存中的临时容器,包括数据库数据在内存中的临时拷贝,它位于数据库与数据库访问中间层,ORM在查询数据时,首先会根据自身的缓存管理策略,在缓存中查找相关数据,如果发现所需的数 ...