您好,登錄后才能下訂單哦!
怎么在vue中使用draggable實現(xiàn)拖拽移動圖片順序?針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
首先,
npm i vuedraggable
然后在組件中引入,
import draggable from 'vuedraggable';
定義組件,
components: { draggable, },
標(biāo)簽中應(yīng)用,
<ul class="pic-list clearfix"> <draggable class="list-group" v-model="hotVOList" :options="{animation: 60,}" :move="getdata" @update="datadragEnd"> <li v-for="(child,index) in hotVOList" :key="index"> <img :src="child.picServerUrl1" > <div class="edit-pop dn"></div> <!-- <div class="edit-box dn"> <span class="banner-edit-btn" @click="eidtBanner(child.id)">編輯</span> <span class="banner-cancle-btn" @click="delateBanner(child.id)">刪除</span> </div> --> <img class="prod-choose" v-if="child.flag == 1" src="../../assets/images/not-select.png" @click="selectProd(child.decorateId)"> <img class="prod-choose" v-else-if="child.flag == 2" src="../../assets/images/prod-select.png" @click="selectProd2(child.decorateId)" > <div class="edit-box-bottom" v-if="child.property == 1"> <span class="conf-con">{{ child.goodsName }}</span> <p class="product-money"><span class="lower">低至</span>¥{{ child.lowestPrice }}</p> </div> <div class="edit-box-bottom" v-else> <span class="conf-con">{{ child.goodsName }}</span> <p class="product-money"> <img src="../../assets/images/yuedu.png" > <span class="browseNum ">{{ child.browseNum }}</span> <img src="../../assets/images/zan.png" > <span class="browseNum ">{{ child.thumbNum }}</span> </p> </div> </li> </draggable> </ul>
方法,
getdata (data) { }, datadragEnd (evt) { var oneId = ""; var otherId = ""; // console.log('datadragEnd方法'); console.log('拖動前的索引 :' + evt.oldIndex) console.log('拖動后的索引 :' + evt.newIndex) if(evt.newIndex == this.hotVOList.length - 1 && this.pageData.pageNum < Math.ceil(this.pageData.total/10)){ this.$api.get("/mallConfig/hot_goods_list/" + this.addHotMallID,{ pageNum:this.pageData.pageNum+1, pageSize:this.pageData.pageSize }, su => { if (su.httpCode == 200) { this.newHotVOList = su.data.hotVOList; oneId = su.data.hotVOList[0].decorateId; otherId = this.hotVOList[evt.newIndex].decorateId; this.$api.get( "/mallConfig/hot_product/exchage_turn/" + this.addHotMallID, { oneId: oneId, otherId :otherId, }, su => { if (su.httpCode == 200) { this.getBodyList(this.addHotMallID); } }, err => {}, { accessToken: sessionStorage.getItem("accessToken") } ); } }, err => {}, { accessToken: sessionStorage.getItem("accessToken") }) } else if(evt.newIndex == this.hotVOList.length - 1 && this.pageData.pageNum == Math.ceil(this.pageData.total/10)){ otherId = this.hotVOList[evt.newIndex].decorateId; oneId = -1; this.$api.get( "/mallConfig/hot_product/exchage_turn/" + this.addHotMallID, { oneId: oneId, otherId :otherId, }, su => { if (su.httpCode == 200) { this.getBodyList(this.addHotMallID); } }, err => {}, { accessToken: sessionStorage.getItem("accessToken") } ); } else { otherId = this.hotVOList[evt.newIndex].decorateId; oneId = this.hotVOList[evt.newIndex + 1].decorateId; this.$api.get( "/mallConfig/hot_product/exchage_turn/" + this.addHotMallID, { oneId: oneId, otherId :otherId, }, su => { if (su.httpCode == 200) { this.getBodyList(this.addHotMallID); } }, err => {}, { accessToken: sessionStorage.getItem("accessToken") } ); } },
關(guān)于怎么在vue中使用draggable實現(xiàn)拖拽移動圖片順序問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。