关于uniapp开发小程序相册拖拽排序组件

115 阅读1分钟

组件代码片段

使用: 模板代码

<view class="drag-box">
    <AlbumDragSort :number="100" v-model="sortList" @onChoose="handleChoose" />
</view>

JS关键代码

 data() {
        return {
            imageList: [],
            sortList: []
        }
    },
    watch: {
        sortList: {
            handler(newVal, oldVal) {
                // console.log('sortList 变化了', newVal);
                this.imageList = newVal
            },
            deep: true
        },
        imageList: {
            handler(newVal, oldVal) {
                // console.log('imageList 变化了', newVal);
                this.sortList = newVal
            },
            deep: true
        }
    },
handleploadImage(images) {
    images.forEach((item, index) => {
        uploadImage({
            path: item.tempFilePath
        }).then(res => {
            if(res.errCode === 0) {
                this.imageList.push(res.data[0])
            }
        })
    })
},
handleChoose(tempFiles) {
    this.handleploadImage(tempFiles)
},