使用element+vuedraggable實(shí)現(xiàn)圖片上傳拖拽排序
本文實(shí)例為大家分享了用element+vuedraggable實(shí)現(xiàn)圖片上傳拖拽排序的具體代碼,供大家參考,具體內(nèi)容如下
<template> ? ? <div class="allUpload"> ? ? ? ? <div class="clearfix"> ? ? ? ? ? ? <div class="wrap"> ? ? ? ? ? ? ? ? <draggable ? ? ? ? ? ? ? ? ? ? v-model="value" ? ? ? ? ? ? ? ? ? ? ? animation="400"? ? ? ? ? ? ? ? ? ? ? class="clearfix" ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? <transition-group> ? ? ? ? ? ? ? ? ? ? ? ? <div class="left middleCenter" v-for="(item,index) in value" :key="item.id"> ? ? ? ? ? ? ? ? ? ? ? ? ? ? <img :src="item.url" alt=""> ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <div class="content-wrap"> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <div class="content middleCenter"> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <i class="el-icon-zoom-in" @click="showImg(item.url)" ></i> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <i class="el-icon-delete" @click="delImg(item,index)"></i> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </div> ? ? ? ? ? ? ? ? ? ? ? ? ? ? </div> ? ? ? ? ? ? ? ? ? ? ? ? </div> ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? </transition-group> ? ? ? ? ? ? ? ? ? ? <div slot="footer" style="float:left"> ? ? ? ? ? ? ? ? ? ? ? ? <el-upload ? ? ? ? ? ? ? ? ? ? ? ? ? ? class="wrap" ? ? ? ? ? ? ? ? ? ? ? ? ? ? list-type="picture-card" ? ? ? ? ? ? ? ? ? ? ? ? ? ? :action="imgUploadUrl" ? ? ? ? ? ? ? ? ? ? ? ? ? ? :show-file-list="false" ? ? ? ? ? ? ? ? ? ? ? ? ? ? :limit="max" ? ? ? ? ? ? ? ? ? ? ? ? ? ? :on-progress="handlePictureCardPreview" ? ? ? ? ? ? ? ? ? ? ? ? ? ? :on-exceed="onExceed" ? ? ? ? ? ? ? ? ? ? ? ? ? ? :disabled="disabled" ? ? ? ? ? ? ? ? ? ? ? ? ? ? :on-change="onChange" ? ? ? ? ? ? ? ? ? ? ? ? ? ? :file-list="fileList" ? ? ? ? ? ? ? ? ? ? ? ? ? ? :multiple="true" ? ? ? ? ? ? ? ? ? ? ? ? ? ? :on-success="handleSuccess" ? ? ? ? ? ? ? ? ? ? ? ? ? ? v-if="isUploadBtn" ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? <i slot="default" :class="uploadLoading ? 'el-icon-loading' : 'el-icon-plus'"></i> ? ? ? ? ? ? ? ? ? ? ? ? </el-upload> ? ? ? ? ? ? ? ? ? ? </div> ? ? ? ? ? ? ? ? </draggable> ? ? ? ? ? ? </div> ? ? ? ? ? ?? ? ? ? ? </div> ? ? ? ?? ? ? ? ? <el-dialog title="查看圖片" :visible.sync="dialogVisible"> ? ? ? ? ? ? <img width="100%" :src="dialogImageUrl" alt=""> ? ? ? ? </el-dialog> ? ? </div> </template> <script> import draggable from 'vuedraggable' import {imgUpload} from '@/api/upload' import {MathRandom} from '@/utils/auth' import { promises } from 'fs' export default { ? ? name:'Upload', ? ? data () { ? ? ? ? return { ? ? ? ? ? ? dialogImageUrl: '', ? ? ? ? ? ? uploadLoading:false, ? ? ? ? ? ? dialogVisible: false, ? ? ? ? ? ? disabled: false, ? ? ? ? ? ? fileList:[], ? ? ? ? ? ? imgUploadUrl:imgUpload(), ? ? ? ? ? ? arrs:[] ? ? ? ? } ? ? }, ? ? props: { ? ? ? ? value: { ? ? ? ? ? ? type: () => [], ? ? ? ? ? ? default () { ? ? ? ? ? ? ? ? return [] ? ? ? ? ? ? } ? ? ? ? }, ? ? ? ? max:{ ? ? ? ? ? ? type:[Number,String], ? ? ? ? ? ? default:9 ? ? ? ? }, ? ? ? ? disabled:{ ? ? ? ? ? ? type:Boolean, ? ? ? ? ? ? default:false ? ? ? ? } ? ? }, ? ? model:{ ? ? ? ? event: 'giveActive' ? ? }, ? ? computed:{ ? ? ? ? isUploadBtn(){ ? ? ? ? ? ? return this.value.length<this.max ? ? ? ? }, ? ? ? ? imgArr(){ ? ? ? ? ? ? return this.value ? ? ? ? } ? ? }, ? ? mounted(){ ? ? ? ? this.value =[] ? ? ? ? // this.fileList =[] ? ? ? ? const unwatch = this.$watch('value', function(newValue, oldValue){ ? ? ? ? ? ? console.log(12312323) ? ? ? ? ? ? this.fileList = newValue ? ? ? ? ? ? unwatch() ? ? ? ? }); ? ? }, ? ? methods: { ? ? ? ? ? ? ? ? go () { ? ? ? ? ? ? this.$emit('giveActive', this.value); ? ? ? ? }, ? ? ? ? showImg(url){ ? ? ? ? ? ? this.dialogImageUrl = url ? ? ? ? ? ? this.dialogVisible = true ? ? ? ? }, ? ? ? ? delImg(item,index){ ? ? ? ? ? ? this.$confirm('此操作將永久刪除該圖片, 是否繼續(xù)?', '提示', { ? ? ? ? ? ? ? ? confirmButtonText: '確定', ? ? ? ? ? ? ? ? cancelButtonText: '取消', ? ? ? ? ? ? ? ? type: 'warning' ? ? ? ? ? ? }).then(() => { ? ? ? ? ? ? ? ? this.value.splice(index,1) ? ? ? ? ? ? ? ? this.fileList.splice(index,1) ? ? ? ? ? ? ? ? this.go() ? ? ? ? ? ? }).catch(() => { ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? }); ? ? ? ? }, ? ? ? ? onChange(file,fileList){ ? ? ? ? ? ? this.fileList = fileList ? ? ? ? }, ? ? ? ?? ? ? ? ? handlePictureCardPreview(file) { ? ? ? ? ? ? this.uploadLoading = true ? ? ? ? }, ? ? ? ? onExceed(files, fileList,props){ ? ? ? ? ? ? this.$message({ ? ? ? ? ? ? ? ? message:`超出最大上傳數(shù)量,最多可上傳${this.max}張圖片`, ? ? ? ? ? ? ? ? type:'error' ? ? ? ? ? ? }) ? ? ? ? }, ? ? ? ? handleSuccess(response, file,fileList) { ? ? ? ? ? ? this.uploadLoading =false ? ? ? ? ? ? this.urlList(response) ? ? ? ? }, ? ? ? ? urlList(res){ ? ? ? ? ? ? const obj={ ? ? ? ? ? ? ? ? id:MathRandom(), ? ? ? ? ? ? ? ? url:res.data.data, ? ? ? ? ? ? ? ? status:'success', ? ? ? ? ? ? ? ? uid:MathRandom() ? ? ? ? ? ? } ? ? ? ? ? ? if(this.value.length<this.max){ ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? this.value = [...this.value,obj] ? ? ? ? ? ? ? ? this.go() ? ? ? ? ? ? } ? ? ? ? ? ?? ? ? ? ? } ? ? } } </script> <style lang='scss' scoped> ? ? .allUpload{ ? ? ? ? .left{ ? ? ? ? ? ? float: left; ? ? ? ? ? ? width: 148px; ? ? ? ? ? ? height: 148px; ? ? ? ? ? ? border-radius: 6px; ? ? ? ? ? ? border: 1px solid #c0ccda; ? ? ? ? ? ? margin:0 20px 20px 0; ? ? ? ? ? ? overflow: hidden; ? ? ? ? ? ? position: relative; ? ? ? ? ? ? cursor: pointer; ? ? ? ? ? ? &:hover{ ? ? ? ? ? ? ? ? .content-wrap{ ? ? ? ? ? ? ? ? ? ? display: block; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? ? ? .content-wrap{ ? ? ? ? ? ? ? ? display: block; ? ? ? ? ? ? } ? ? ? ? ? ? img{ ? ? ? ? ? ? ? ? max-width: 100%; ? ? ? ? ? ? ? ? max-height: 100%; ? ? ? ? ? ? ? ? object-fit: cover; ? ? ? ? ? ? } ? ? ? ? ? ? .content-wrap{ ? ? ? ? ? ? ? ? display: none; ? ? ? ? ? ? ? ? position: absolute; ? ? ? ? ? ? ? ? z-index: 99999999; ? ? ? ? ? ? ? ? width: 100%; ? ? ? ? ? ? ? ? height: 100%; ? ? ? ? ? ? ? ? background:rgba($color: #000000, $alpha: 0.4); ? ? ? ? ? ? ? ? .content{ ? ? ? ? ? ? ? ? ? ? width: 100%; ? ? ? ? ? ? ? ? ? ? height: 100%; ? ? ? ? ? ? ? ? ? ? i{ ? ? ? ? ? ? ? ? ? ? ? ? color: #fff; ? ? ? ? ? ? ? ? ? ? ? ? font-size: 18px; ? ? ? ? ? ? ? ? ? ? ? ? &:nth-of-type(1){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? margin-right: 10px; ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? &:nth-of-type(2){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? margin-left: 10px; ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? ? ?? ? ? ? ? } ? ? ? ?? ? ? ? ? .wrap{ ? ? ? ? ? ? float: left; ? ? ? ? } ? ? } </style>
效果圖
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue3中使用vuedraggable拖拽實(shí)戰(zhàn)教程
- vue使用vuedraggable實(shí)現(xiàn)嵌套多層拖拽排序功能
- vue拖拽組件vuedraggable使用說(shuō)明詳解
- 使用vuedraggable實(shí)現(xiàn)從左向右拖拽功能
- vue3使用vuedraggable實(shí)現(xiàn)拖拽功能
- vuedraggable實(shí)現(xiàn)拖拽功能
- vuedraggable+element ui實(shí)現(xiàn)頁(yè)面控件拖拽排序效果
- vue拖拽排序插件vuedraggable使用方法詳解
- vue使用vuedraggable插件實(shí)現(xiàn)拖拽效果
相關(guān)文章
VueJs使用Amaze ui調(diào)整列表和內(nèi)容頁(yè)面
這篇文章主要介紹了VueJs 填坑日記之使用Amaze ui調(diào)整列表和內(nèi)容頁(yè)面,需要的朋友可以參考下2017-11-11vue項(xiàng)目總結(jié)之文件夾結(jié)構(gòu)配置詳解
這篇文章主要給大家總結(jié)介紹了關(guān)于vue項(xiàng)目之文件夾結(jié)構(gòu)配置的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12Vue.js彈出模態(tài)框組件開(kāi)發(fā)的示例代碼
本篇文章主要介紹了Vue.js彈出模態(tài)框組件開(kāi)發(fā)的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07VueJS 組件參數(shù)名命名與組件屬性轉(zhuǎn)化問(wèn)題
這篇文章主要介紹了VueJS 組件參數(shù)名命名與組件屬性轉(zhuǎn)化問(wèn)題,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-12-12vue實(shí)現(xiàn)下拉框二級(jí)聯(lián)動(dòng)效果的實(shí)例代碼
這篇文章主要介紹了vue實(shí)現(xiàn)下拉框二級(jí)聯(lián)動(dòng)效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-11-11如何使用 vue-cli 創(chuàng)建模板項(xiàng)目
這篇文章主要介紹了如何使用 vue-cli 創(chuàng)建模板項(xiàng)目,幫助大家更好的理解和學(xué)習(xí)vue框架的知識(shí),感興趣的朋友可以了解下2020-11-11淺談vue中使用圖片懶加載vue-lazyload插件詳細(xì)指南
本篇文章主要介紹了淺談vue中使用圖片懶加載vue-lazyload插件詳細(xì)指南,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-10-10