赞
踩
awe-dnd和vue-draggable做了一番比较,最终选择了vue-draggable,至于原因:
各项配置介绍:vuedraggable文文档
1.安装 npm或者yarn
- yarn add vuedraggable
- npm i -S vuedraggable
2.在vue项目中引入draggable
- //导入draggable组件
- import draggable from 'vuedraggable';
- ......
- export default {
- components: {
- draggable,
- },
- data() {
- return {
- imageUrlList: []
- };
- },
- methods: {
- /**
- * @description: 预览的图片添加下载按钮
- */
- clickImage() {
-
- },
-
- /**
- * @description: 查看-大图预览, 先看当前大图
- * @param {Number} index 当前下标
- * @param {Array} imgList 所有大图
- * @return {Array} arr 当前图片为第一个的大图
- */
- getPreviewList(index, imgList) {
- let arr = [];
- let i = 0;
- for (i; i < imgList.length; i++) {
- arr.push(imgList[i + index].fileUrl);
- if (i + index >= imgList.length - 1) {
- index = 0 - (i + 1);
- }
- }
- return arr;
- },
-
-
- }
-
- };
3.在模板中使用draggable
- <draggable
- v-model="imageUrlList"
- animation="300"
- draggable=".drag-area"
- >
- <div
- class="drag-area"
- v-for="(item, index) in imageUrlList"
- :key="item.fileName"
- >
- <el-image
- @click.stop.prevent="clickImage"
- :src="item.fileUrl"
- :preview-src-list="getPreviewList(index, imageUrlList)"
- >
- <div slot="error" class="image-slot">
- <i class="el-icon-picture-outline"></i>
- </div>
- </el-image>
- </div>
- <div class="el-upload__text">
- <em>点击上传</em>
- </div>
- </draggable>
以下几点需要注意
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。