<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        vue上傳圖片到oss的方法示例(圖片帶有刪除功能)

        來源:懂視網 責編:小采 時間:2020-11-27 22:07:02
        文檔

        vue上傳圖片到oss的方法示例(圖片帶有刪除功能)

        vue上傳圖片到oss的方法示例(圖片帶有刪除功能):最近Vue項目中,要將用戶上傳的圖片全部上傳到oss上, OSS配置項請訪問:https://help.aliyun.com/document_detail/64095.html?spm=a2c4g.11186623.6.773.kcD20n OSS平臺配置 在平臺的概覽里面看看自己的基礎設置里面的讀寫權限是否改為了
        推薦度:
        導讀vue上傳圖片到oss的方法示例(圖片帶有刪除功能):最近Vue項目中,要將用戶上傳的圖片全部上傳到oss上, OSS配置項請訪問:https://help.aliyun.com/document_detail/64095.html?spm=a2c4g.11186623.6.773.kcD20n OSS平臺配置 在平臺的概覽里面看看自己的基礎設置里面的讀寫權限是否改為了

        最近Vue項目中,要將用戶上傳的圖片全部上傳到oss上,

        OSS配置項請訪問:https://help.aliyun.com/document_detail/64095.html?spm=a2c4g.11186623.6.773.kcD20n

        OSS平臺配置

        在平臺的概覽里面看看自己的基礎設置里面的讀寫權限是否改為了公共讀,我這邊只有配置公共讀才上傳并且回顯圖片成功,其他情況還請朋友告知,謝謝

        關于跨域訪問的配置

        這里是我的效果圖 (當只有點擊上傳按鈕時才會上傳到OSS)

        預覽圖片

        <template>
         <div class="vue-uploader">
         <div class="file-list">
         <section v-for="(file, index) of files" class="file-item draggable-item" :key="file.name">
         <img :src="file.src" alt="" ondragstart="return false;">
         <span class="file-remove" @click="remove(index)">+</span>
         </section>
         <section v-if="status == 'ready'" class="file-item">
         <div @click="add" class="add"></div>
         </section>
         </div>
         <section v-if="files.length != 0" class="upload-func">
         <div class="progress-bar">
         <section v-if="uploading" :width="(percent * 100) + '%'">{{(percent * 100) + '%'}}</section>
         </div>
         <div class="operation-box">
         <button v-if="status == 'ready'" @click="submit">上傳</button>
         <button v-if="status == 'finished'" @click="finished">完成</button>
         </div>
         </section>
         <input type="file" @change="fileChanged" ref="file" multiple="multiple" accept="image/jpg,image/jpeg,image/png,image/bmp">
         </div>
        </template>
        <script>
         export default {
         data() {
         return {
         status: 'ready',
         files: [],
         point: {},
         uploading: false,
         percent: 0
         }
         },
         methods: {
         add() {
         this.$refs.file.click()
         },
         submit() {
         console.log(this.files)
         // if (this.files.length === 0) {
         // console.warn('no file!');
         // return
         // }
         var that=this
         // 這里是OSS
         const client = new OSS.Wrapper({
         region: 'oss-cn-hangzhou', 
         accessKeyId: 'your access key',
         accessKeySecret: 'your access secret',
         bucket: 'your bucket name'
         });
         const fNum = this.files;
         for(var i=0;i<fNum.length;i++){
         var f=fNum[i].file
         console.log(f)
         const Name=f.name
         console.log(Name)
         const suffix = Name.substr(Name.indexOf("."));
         const obj=this.timestamp();
         const storeAs = 'header/'+obj+suffix // 路徑+時間戳+后綴名
         console.log(storeAs)
         client.multipartUpload(storeAs, f).then(function (result){
         console.log(result.res.requestUrls)
         })
         }
         },
         // 時間戳
         timestamp:function(){ 
         const time = new Date(); 
         const y = time.getFullYear(); 
         const m = time.getMonth()+1; 
         const d = time.getDate(); 
         const h = time.getHours(); 
         const mm = time.getMinutes(); 
         const s = time.getSeconds(); 
         const ms = time.getMilliseconds() 
         return ""+y+this.Add0(m)+this.Add0(d)+this.Add0(h)+this.Add0(mm)+this.Add0(s)+this.Add0(ms); 
         },
         Add0:function(m){ 
         return m<10?'0'+m : m; 
         } ,
        
         finished() {
         this.files = []
         this.status = 'ready'
         
         },
         remove(index) {
         this.files.splice(index, 1)
         },
         fileChanged() {
         const list = this.$refs.file.files
         for (let i = 0; i < list.length; i++) {
         if (!this.isContain(list[i])) {
         const item = {
         name: list[i].name,
         size: list[i].size,
         file: list[i]
         }
         this.html5Reader(list[i], item)
         this.files.push(item)
         }
         }
         this.$refs.file.value = ''
         },
         // 將圖片文件轉成BASE64格式
         html5Reader(file, item){
         const reader = new FileReader()
         reader.onload = (e) => {
         this.$set(item, 'src', e.target.result)
         }
         reader.readAsDataURL(file)
         },
         isContain(file) {
         return this.files.find((item) => item.name === file.name && item.size === file.size)
         },
         }
         }
        </script>
        <style>
        .vue-uploader {
         border: 1px solid #e5e5e5;
        }
        .vue-uploader .file-list {
         padding: 10px 0px;
        }
        .vue-uploader .file-list:after {
         content: '';
         display: block;
         clear: both;
         visibility: hidden;
         line-height: 0;
         height: 0;
         font-size: 0;
        }
        .vue-uploader .file-list .file-item {
         float: left;
         margin-left: 10px;
         
         position: relative;
         width: 150px;
         text-align: center;
        }
        .vue-uploader .file-list .file-item img{
         width: 150px;
         height: 150px;
         border: 1px solid #ececec;
        }
        .vue-uploader .file-list .file-item .file-remove {
         position: absolute;
         right: 4px;
         display: none;
         top: 4px;
         width: 20px;
         height: 20px;
         font-size:20px;
         text-align: center;
         color: white;
         cursor: pointer;
         line-height: 20px;
         border-radius: 100%;
         transform: rotate(45deg);
         background: rgba(0, 0, 0, 0.5);
        }
        .vue-uploader .file-list .file-item:hover .file-remove {
         display: inline;
        }
        .vue-uploader .file-list .file-item .file-name {
         margin: 0;
         height: 40px;
         word-break: break-all;
         font-size: 14px;
         overflow: hidden;
         text-overflow: ellipsis;
         display: -webkit-box;
         -webkit-line-clamp: 2;
         -webkit-box-orient: vertical;
        }
        .vue-uploader .add {
         width: 150px;
         height: 150px;
         float: left;
         text-align: center;
         line-height: 150px;
         font-size: 30px;
         cursor: pointer;
         background: url(../assets/upImg.png) no-repeat; // 這里使用的是我本地圖片
         background-size: 100% 100%;
        }
        .vue-uploader .upload-func {
         display: flex;
         padding: 10px;
         margin: 0px;
         background: #f8f8f8;
         border-top: 1px solid #ececec;
        }
        .vue-uploader .upload-func .progress-bar {
         flex-grow: 1;
        }
        .vue-uploader .upload-func .progress-bar section {
         margin-top: 5px;
         background: #00b4aa;
         border-radius: 3px;
         text-align: center; 
         color: #fff;
         font-size: 12px;
         transition: all .5s ease;
        }
        .vue-uploader .upload-func .operation-box {
         flex-grow: 0;
         padding-left: 10px;
        }
        .vue-uploader .upload-func .operation-box button {
         padding: 4px 12px;
         color: #fff;
         background: #007ACC;
         border: none;
         border-radius: 2px;
         cursor: pointer;
        }
        .vue-uploader > input[type="file"] {
         display: none;
        }
        </style>
        
        

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        vue上傳圖片到oss的方法示例(圖片帶有刪除功能)

        vue上傳圖片到oss的方法示例(圖片帶有刪除功能):最近Vue項目中,要將用戶上傳的圖片全部上傳到oss上, OSS配置項請訪問:https://help.aliyun.com/document_detail/64095.html?spm=a2c4g.11186623.6.773.kcD20n OSS平臺配置 在平臺的概覽里面看看自己的基礎設置里面的讀寫權限是否改為了
        推薦度:
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 久久久久亚洲av无码专区导航| 色窝窝免费一区二区三区| 亚洲国产综合无码一区二区二三区 | 两个人日本免费完整版在线观看1| 日本三级2019在线观看免费| 亚洲美女aⅴ久久久91| 亚洲免费福利视频| 国产成人精品日本亚洲网址| 成年18网站免费视频网站| 亚洲乱亚洲乱妇无码| 国产免费卡一卡三卡乱码| 日韩电影免费在线观看网址| 亚洲无av在线中文字幕| 成人黄网站片免费视频| 亚洲精品国产第1页| 日韩中文字幕免费| 一级人做人爰a全过程免费视频| 亚洲最大AV网站在线观看| 午夜精品射精入后重之免费观看| 亚洲视频中文字幕在线| 大学生高清一级毛片免费| 色偷偷亚洲男人天堂| 国产亚洲成归v人片在线观看| 中文成人久久久久影院免费观看| 久久亚洲AV成人无码| 女人与禽交视频免费看| 一级毛片免费在线| 亚洲人成亚洲精品| 麻豆最新国产剧情AV原创免费 | 亚洲国产精品lv| 色播精品免费小视频| 亚洲色欲色欲www在线播放| 哒哒哒免费视频观看在线www | 亚洲第一香蕉视频| 四虎精品视频在线永久免费观看| 亚洲狠狠色丁香婷婷综合| 在线观看亚洲av每日更新| 无码av免费毛片一区二区| 日本激情猛烈在线看免费观看| 亚洲综合精品一二三区在线| 国产传媒在线观看视频免费观看|