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

坑3.上传图片(阿里云空间,oss验证)(未验证)

 笔记

20240710   未验证,现在还没有阿里云空间,等买个sit环境就可以验证一下。

 前端

        页面
<!--页面-->
<el-form-item label="优惠券图片" prop="couponImg"><single-upload v-model="dataForm.couponImg"></single-upload>
</el-form-item><!--vue引入-->
import SingleUpload from "@/components/upload/singleUpload";<!--vue对象里加组件-->
components: { SingleUpload },<!--保存方法,couponImg就是url路径-->
        组件
<template> <div><!-- action必选参数,上传地址,bucket的外网访问域名 --><el-uploadaction="https://vivi-gulimall.oss-cn-hangzhou.aliyuncs.com":data="dataObj"list-type="picture":multiple="false" :show-file-list="showFileList":file-list="fileList":before-upload="beforeUpload":on-remove="handleRemove":on-success="handleUploadSuccess":on-preview="handlePreview"><el-button size="small" type="primary">点击上传</el-button><div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过10MB</div></el-upload><el-dialog :visible.sync="dialogVisible"><img width="100%" :src="fileList[0].url" alt=""></el-dialog></div>
</template>
<script>import {policy} from './policy'import { getUUID } from '@/utils'export default {name: 'singleUpload',props: {value: String},computed: {imageUrl() {return this.value;},imageName() {if (this.value != null && this.value !== '') {return this.value.substr(this.value.lastIndexOf("/") + 1);} else {return null;}},fileList() {return [{name: this.imageName,url: this.imageUrl}]},showFileList: {get: function () {return this.value !== null && this.value !== ''&& this.value!==undefined;},set: function (newValue) {}}},data() {return {dataObj: {policy: '',signature: '',key: '',ossaccessKeyId: '',dir: '',host: '',// callback:'',},dialogVisible: false};},methods: {emitInput(val) {this.$emit('input', val)},handleRemove(file, fileList) {this.emitInput('');},handlePreview(file) {this.dialogVisible = true;},beforeUpload(file) {let _self = this;return new Promise((resolve, reject) => {policy().then(response => {_self.dataObj.policy = response.data.policy;_self.dataObj.signature = response.data.signature;_self.dataObj.ossaccessKeyId = response.data.accessid;_self.dataObj.key = response.data.dir + getUUID() + '_${filename}';_self.dataObj.dir = response.data.dir;_self.dataObj.host = response.data.host;console.log("上传前请求服务端签名,得到结果:", _self.dataObj)resolve(true)}).catch(err => {reject(false)})})},handleUploadSuccess(res, file) {console.log("上传成功...")this.showFileList = true;this.fileList.pop();this.fileList.push({name: file.name, url: this.dataObj.host + '/' + this.dataObj.key.replace("${filename}",file.name) });this.emitInput(this.fileList[0].url);}}}
</script>
<style></style>

http://www.lryc.cn/news/400474.html

相关文章:

  • 注册登录后上传文件到本地数据库项目
  • 【学习笔记】无人机(UAV)在3GPP系统中的增强支持(十三)-更换无人机控制器
  • react 组件通信 —— 父子传值 【 函数式/类式 】
  • 【SpringBoot】95、SpringBoot中使用MyBatis-Plus实现自动加密存储和查询自动解密
  • [数仓]十二、离线数仓(Atlas元数据管理)
  • 机器学习——决策树(笔记)
  • 翁恺-C语言程序设计-08-1. 求一批整数中出现最多的个位数字
  • ROM修改进阶教程------深度解析小米设备锁机型不解锁bl 刷写特殊类固件的步骤
  • 论文翻译 | LEAST-TO-MOST: 从最少到最多的提示使大型语言模型中的复杂推理成为可能
  • 【区块链 + 智慧政务】都江堰区块链公共服务应用平台 | FISCO BCOS应用案例
  • Python从0到100(三十九):数据提取之正则(文末免费送书)
  • redis redisson(仅供自己参考)
  • 【C语言初阶】探索编程基础:深入理解分支与循环语句的奥秘
  • ERP基础知识
  • C++是否可以使用.获取union、struct中的成员变量的地址
  • 【前端】包管理器:npm、Yarn 和 pnpm 的全面比较
  • C++ 类和对象 赋值运算符重载
  • 【Python实战因果推断】35_双重差分6
  • 【HarmonyOS】关于官方推荐的组件级路由Navigation的心得体会
  • Spring中事件监听器
  • 案例|LabVIEW连接S7-1200PLC
  • 正点原子STM32(基于HAL库)6
  • flutter Android端权限
  • ant design form动态增减表单项Form.List如何进行动态校验规则
  • 7.16做题总结
  • unity使用 MQTT复现plant simulate仿真
  • MATLAB激光通信和-积消息传递算法(Python图形模型算法)模拟调制
  • 初识HTML
  • 基于Rspack实现大仓应用构建提效实践|得物技术
  • 什么是MOW,以bitget钱包为例