中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

瑞麗網(wǎng)站建設(shè)深圳整站seo

瑞麗網(wǎng)站建設(shè),深圳整站seo,做網(wǎng)站的公司合肥,常見網(wǎng)站建設(shè)公司術(shù)語要在 Element UI 的拖拽上傳組件中實現(xiàn) Ctrl V 圖片上傳功能,可以通過監(jiān)聽鍵盤事件來捕獲粘貼操作,并將粘貼的圖片數(shù)據(jù)上傳到服務(wù)器。 版本V1,實現(xiàn)獲取粘貼板中的文件 注意,本案例需要再你已經(jīng)安裝了Element UI并在項目中正確配…

要在 Element UI 的拖拽上傳組件中實現(xiàn) Ctrl + V 圖片上傳功能,可以通過監(jiān)聽鍵盤事件來捕獲粘貼操作,并將粘貼的圖片數(shù)據(jù)上傳到服務(wù)器。

版本V1,實現(xiàn)獲取粘貼板中的文件

注意,本案例需要再你已經(jīng)安裝了Element UI并在項目中正確配置的情況下進行,第一個版本僅適合上傳jpeg和png的圖片

創(chuàng)建拖拽上傳組件
假設(shè)你已經(jīng)有一個基本的拖拽上傳組件,我們可以在此基礎(chǔ)上添加 Ctrl + V 功能。

監(jiān)聽粘貼事件
我們需要在頁面中監(jiān)聽 paste 事件,當用戶按下 Ctrl + V 時,捕獲粘貼板中的圖片數(shù)據(jù)。

處理粘貼事件

在捕獲到圖片數(shù)據(jù)后,將其轉(zhuǎn)換為 File 對象,并調(diào)用上傳方法。

代碼如下:

<template><div><el-uploaddragaction="https://jsonplaceholder.typicode.com/posts/":on-preview="handlePreview":on-remove="handleRemove":before-upload="beforeUpload"multipleref="upload"><i class="el-icon-upload"></i><div class="el-upload__text">將文件拖到此處,或<em>點擊上傳</em></div><div class="el-upload__tip" slot="tip">只能上傳jpg/png文件,且不超過500kb</div></el-upload></div>
</template>
<script>
import { Upload } from 'element-ui';export default {name: 'DragUpload',methods: {handlePaste(event) {// 捕獲粘貼事件const items = event.clipboardData.items;for (let i = 0; i < items.length; i++) {if (items[i].type.indexOf('image') !== -1) {// 獲取圖片文件const file = items[i].getAsFile();this.handleFile(file);break;}}},handleFile(file) {// 將文件添加到上傳隊列this.$refs.upload.handleStart(file);this.$refs.upload.submit();},handlePreview(file) {console.log('Preview:', file);},handleRemove(file, fileList) {console.log('Remove:', file, fileList);},beforeUpload(file) {const isJPGorPNG = file.type === 'image/jpeg' || file.type === 'image/png';const isLt500K = file.size / 1024 < 500;if (!isJPGorPNG) {this.$message.error('只能上傳 JPG/PNG 格式的圖片!');}if (!isLt500K) {this.$message.error('圖片大小不能超過 500KB!');}return isJPGorPNG && isLt500K;}},mounted() {// 監(jiān)聽粘貼事件document.addEventListener('paste', this.handlePaste);},beforeDestroy() {// 移除粘貼事件監(jiān)聽document.removeEventListener('paste', this.handlePaste);}
};
</script>
  1. HTML部分:使用 el-upload 組件創(chuàng)建一個拖拽上傳區(qū)域。
  2. JavaScript部分:
    • handlePaste 方法:捕獲粘貼事件,檢查粘貼板中的數(shù)據(jù)是否為圖片文件,如果是,則調(diào)用 handleFile 方法。
    • handleFile 方法:將圖片文件添加到上傳隊列,并提交上傳。
    • mounted 生命周期鉤子:添加粘貼事件監(jiān)聽器。
    • beforeDestroy 生命周期鉤子:移除粘貼事件監(jiān)聽器,防止內(nèi)存泄漏。

隨便截圖一張,我們這個時候ctrl + v 就可以發(fā)現(xiàn)他可以獲取我們粘貼板中的文件。

在這里插入圖片描述
在這里插入圖片描述
我們到這一步發(fā)現(xiàn),圖片網(wǎng)頁是獲取到。這個時候你在跟著你的業(yè)務(wù),傳遞相關(guān)參數(shù),這第V1版本就可以用了。

第二版本V2,可以直接在粘貼的過程在下面以壓縮圖片的形式展示圖片

<template><div><el-uploaddrag:action="uploadFileUrl":on-preview="handlePreview":on-remove="handleRemove":before-upload="beforeUpload":on-success="handleSuccess"multipleref="upload":file-list="fileList"><i class="el-icon-upload"></i><div class="el-upload__text">將文件拖到此處,或<em>點擊上傳</em></div><div class="el-upload__tip" slot="tip">只能上傳jpg/png文件,且不超過500kb</div></el-upload><!-- 顯示上傳后的文件 --><div v-for="(file, index) in fileList" :key="index" class="uploaded-file"><div v-if="isImage(file.name)"><img :src="file.url" alt="Uploaded Image" class="uploaded-image" /><el-button type="text" @click="removeFile(index)">移除</el-button></div><div v-else><span>{{ file.name }}</span><el-button type="text" @click="removeFile(index)">移除</el-button></div></div></div>
</template>
<script>
import { Upload } from 'element-ui';export default {name: 'DragUpload',data() {return {fileList: []};},methods: {handlePaste(event) {const items = event.clipboardData.items;for (let i = 0; i < items.length; i++) {if (items[i].type.indexOf('image') !== -1) {const file = items[i].getAsFile();this.handleFile(file);break;}}},handleFile(file) {const reader = new FileReader();reader.onload = (e) => {this.fileList.push({name: file.name,url: e.target.result});};reader.readAsDataURL(file);this.$refs.upload.handleStart(file);this.$refs.upload.submit();},handlePreview(file) {console.log('Preview:', file);},handleRemove(file, fileList) {this.fileList = fileList;},beforeUpload(file) {const isJPGorPNG = file.type === 'image/jpeg' || file.type === 'image/png';const isLt500K = file.size / 1024 < 500;if (!isJPGorPNG) {this.$message.error('只能上傳 JPG/PNG 格式的圖片!');}if (!isLt500K) {this.$message.error('圖片大小不能超過 500KB!');}return isJPGorPNG && isLt500K;},handleSuccess(response, file, fileList) {// 更新 fileListthis.fileList = fileList.map(f => ({name: f.name,url: f.url || f.response.url // 假設(shè)服務(wù)器返回的響應中有 url 字段}));},removeFile(index) {this.fileList.splice(index, 1);},isImage(fileName) {return fileName.toLowerCase().endsWith('.jpg') || fileName.toLowerCase().endsWith('.png');}},mounted() {document.addEventListener('paste', this.handlePaste);},beforeDestroy() {document.removeEventListener('paste', this.handlePaste);}
};
</script>
<style scoped>
.uploaded-file {margin-top: 10px;display: flex;align-items: center;
}.uploaded-image {max-width: 100px;max-height: 100px;margin-right: 10px;
}
</style>

在這里插入圖片描述

在這里插入圖片描述
如圖所示。Ctrl + V就實現(xiàn)到了這一步。這里有問題,那就是你看一下,點擊上傳后的圖片是否會顯示出來呢?

http://www.risenshineclean.com/news/31494.html

相關(guān)文章:

  • 湖南做網(wǎng)站 真好磐石網(wǎng)絡(luò)東莞公司網(wǎng)上推廣
  • 網(wǎng)站建設(shè)銷售發(fā)展前景百度指數(shù)關(guān)鍵詞搜索趨勢
  • 英文seo公司seo文章
  • 網(wǎng)站域名使用期怎么去推廣自己的店鋪
  • 做ar的網(wǎng)站搜資源的搜索引擎
  • 婦聯(lián)網(wǎng)站建設(shè)方案搜索歷史記錄
  • 熟人做網(wǎng)站怎么收錢湖南seo服務(wù)電話
  • 東昌網(wǎng)站建設(shè)網(wǎng)站建設(shè)策劃書案例
  • 做網(wǎng)站用的云控制臺活動推廣軟文范例
  • 重慶有什么好玩的旅游景點寧波seo外包優(yōu)化
  • 濟南制作網(wǎng)站的公司哪家好汕頭網(wǎng)站建設(shè)優(yōu)化
  • 網(wǎng)站被墻301怎么做付費推廣平臺有哪些
  • 科威網(wǎng)絡(luò)做網(wǎng)站怎么樣html網(wǎng)頁制作app
  • 網(wǎng)站建設(shè)合同是否繳納印花稅中國網(wǎng)站排名查詢
  • 金寨縣建設(shè)規(guī)劃局網(wǎng)站信息流廣告有哪些投放平臺
  • 做夾具需要知道的幾個網(wǎng)站企業(yè)網(wǎng)站seo方案
  • 中億豐建設(shè)集團股份有限公司網(wǎng)站百度競價是什么工作
  • 學做餅干網(wǎng)站發(fā)稿網(wǎng)
  • 行業(yè)門戶網(wǎng)站模板中國剛剛發(fā)生8件大事
  • 如何開發(fā)app小程序win優(yōu)化大師
  • 北京市文化局政務(wù)網(wǎng)站建設(shè)項目獨立站seo怎么做
  • 深圳網(wǎng)站制作鄭州怎么優(yōu)化網(wǎng)站排名靠前
  • 南通seo公司網(wǎng)站免費推廣產(chǎn)品平臺有哪些
  • 上海奉賢 網(wǎng)站建設(shè)百度指數(shù)查詢移動版
  • 廉江網(wǎng)站建設(shè)公眾號推廣合作平臺
  • html網(wǎng)頁設(shè)計基礎(chǔ)seo優(yōu)化主要做什么
  • 網(wǎng)站開發(fā)者模式企業(yè)官網(wǎng)建站
  • 學網(wǎng)站建設(shè)需要什么軟件百度外包公司有哪些
  • 企業(yè)網(wǎng)站建設(shè)參考資料競價推廣賬戶競價托管
  • 珠海服務(wù)好的網(wǎng)站建設(shè)武漢seo