欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vuedraggable實現(xiàn)拖拽功能

 更新時間:2022年04月06日 09:06:58   作者:EsquireY  
這篇文章主要為大家詳細(xì)介紹了vuedraggable實現(xiàn)拖拽功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了vuedraggable實現(xiàn)拖拽功能的具體代碼,供大家參考,具體內(nèi)容如下

項目需求

簡單實現(xiàn)一個vue拖拽小案例,右側(cè)選項區(qū)拖拽到左側(cè)目標(biāo)區(qū)域,拖動成功的不能再次拖動,并改變顏色。

安裝 vuedraggable 插件

cnpm i -S vuedraggable

頁面直接引用

import draggable from “vuedraggable”;
…
components: { draggable },

源碼參考

<template>
? <div class="container">
? ? <div class="content">
? ? ? <div class="targetContent">
? ? ? ? <draggable
? ? ? ? ? :list="resultlists"
? ? ? ? ? group="article"
? ? ? ? ? :disabled="disabled"
? ? ? ? ? @start="targetStart"
? ? ? ? ? @end="targetEnd"
? ? ? ? ? class="targetCard"
? ? ? ? ? style="height: 100px"
? ? ? ? >
? ? ? ? ? <div
? ? ? ? ? ? v-for="resultlists in resultlists"
? ? ? ? ? ? :key="resultlists.id"
? ? ? ? ? ? class="list-complete-item"
? ? ? ? ? >
? ? ? ? ? ? <div class="list-complete-item-handle">{{ resultlists.name }}</div>
? ? ? ? ? </div>
? ? ? ? </draggable>
? ? ? </div>
? ? ? <div class="optionsContent">
? ? ? ? <draggable
? ? ? ? ? :list="targetLists"
? ? ? ? ? :options="{
? ? ? ? ? ? group: { name: optionsName, pull: 'clone' },
? ? ? ? ? ? sort: false,
? ? ? ? ? }"
? ? ? ? ? filter=".undraggable"
? ? ? ? ? @end="optionEnd"
? ? ? ? ? class="dragArea"
? ? ? ? >
? ? ? ? ? <div
? ? ? ? ? ? v-for="targetList in targetLists"
? ? ? ? ? ? :key="targetList.id"
? ? ? ? ? ? :class="{ undraggable: targetList.flag }"
? ? ? ? ? ? class="list-complete-item"
? ? ? ? ? >
? ? ? ? ? ? <div class="list-complete-item-handle2">{{ targetList.name }}</div>
? ? ? ? ? </div>
? ? ? ? </draggable>
? ? ? </div>
? ? </div>
? </div>
</template>
<script>
import draggable from "vuedraggable";

export default {
? name: "DndList",
? components: { draggable },
? watch: {},
? data() {
? ? return {
? ? ? optionsName: "article",
? ? ? disabled: false,
? ? ? resultlists: [],
? ? ? targetLists: [
? ? ? ? { id: 1, name: "平板支撐" },
? ? ? ? { id: 2, name: "俄挺" },
? ? ? ? { id: 3, name: "空中自行車" },
? ? ? ? { id: 4, name: "波比" },
? ? ? ? { id: 5, name: "兩頭起摸腳" },
? ? ? ? { id: 6, name: "窄距俯臥撐" },
? ? ? ? { id: 7, name: "寬距俯臥撐" },
? ? ? ? { id: 8, name: "鉆石俯臥撐" },
? ? ? ? { id: 9, name: "空中擊掌俯臥稱" },
? ? ? ? { id: 10, name: "深蹲提膝跳" },
? ? ? ],
? ? };
? },
? computed: {},
? methods: {
? ?? ?// 右側(cè)拖拽結(jié)束事件
? ? optionEnd(ev) {
? ? // 如果拖拽目標(biāo)區(qū)域和左側(cè)區(qū)域的 name 一致,允許拖拽,并改變狀態(tài)
? ? ? if (ev.to.className === "targetCard") {
? ? ? ? this.$set(this.targetLists[ev.oldIndex], "flag", true);
? ? ? }
? ? },
?? ?// 左側(cè)區(qū)域開始拖動事件(修改右側(cè)區(qū)域的名字,不一致的話拖動失?。?
? ? targetStart() {
? ? ? this.optionsName = "1111";
? ? },
?? ?// 拖動結(jié)束時,把右側(cè)區(qū)域的名字恢復(fù)
? ? targetEnd() {
? ? ? this.optionsName = "article";
? ? },
? },
};
</script>

<style lang="less" scoped>
.container {
? width: 100%;
? height: 100%;
? background-color: rgba(5, 35, 56, 0.6);
? display: flex;
? align-items: center;
? justify-content: center;
? .content {
? ? width: 1200px;
? ? height: 600px;
? ? background-color: #052338;
? ? // margin: 120px auto auto;
? ? display: flex;

? ? .targetContent {
? ? ? width: 100%;
? ? ? height: 100%;
? ? }

? ? .optionsContent {
? ? ? width: 100%;
? ? ? height: 100%;
? ? ? border-left: 2px solid #4ab7bd;
? ? }
? }
}
.list-complete-item {
? display: inline-block;
? font-size: 16px;
? font-weight: 400;
? color: #ffffff;
? padding: 10px 18px;
? margin: 10px 8px 0;
? background: rgba(237, 245, 255, 0.1);
? border: 1px solid #bfcbd9;
? border-radius: 0.18rem;
? cursor: pointer;
? transition: all 1s;
}

.list-complete-item.sortable-chosen {
? background: #4ab7bd;
}

.list-complete-item.sortable-ghost {
? background: #30b08f;
}
.undraggable {
? background-color: rgb(143, 233, 233);
}

.list-complete-enter,
.list-complete-leave-active {
? opacity: 0;
}
</style>

常用事件

@start = "startChange" // 開始拖動元素觸發(fā)的事件
@end= "endChange" // 拖動元素結(jié)束觸發(fā)的事件

常用屬性配置

:options="{
?? ?group: { name: optionsName, pull: 'clone' }, // name 相同的集合子元素可以互相拖動
? ? sort: false, // 是否禁止拖動排序
? ? disabled: false, // 如果設(shè)置為真,則禁用sortable。
? ? animation: 150, ?// ms, 動畫速度運動項目排序時,' 0 ' -沒有動畫。
? ? filter: ".ignore-elements", ?// 不導(dǎo)致拖拽的選擇器(字符串或函數(shù))
? ? draggable: ".item", ?// 指定元素中的哪些項應(yīng)該是可拖動的。
? ?? ?ghostClass: "sortable-ghost", ?// 設(shè)置拖動元素的class的占位符的類名。
? ?? ?chosenClass: "sortable-chosen", ?// 設(shè)置被選中的元素的class
? ?? ?dragClass: "sortable-drag", ?//拖動元素的class。
? }"

注意事項

1、拖動的時間元素失去樣式

選項區(qū)域和目標(biāo)區(qū)域的元素樣式不一致

2、拖動失敗

選項區(qū)域和目標(biāo)區(qū)域的名字不一致,會導(dǎo)致拖動失敗

3、控制臺報提示( props is deprecated, add sortable options directly as vue.draggable item, or use v-bind…)

插件版本問題,:options="{}" 的寫法已經(jīng)被棄用,直接使用 v-bind 寫法,具體參照介紹

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue項目報錯:Missing?script:"serve"的解決辦法

    vue項目報錯:Missing?script:"serve"的解決辦法

    這篇文章主要給大家介紹了關(guān)于vue項目報錯:Missing?script:"serve"的解決辦法,"missing script: serve"是一個錯誤信息,意味著在執(zhí)行啟動腳本時,找不到名為"serve"的腳本,需要的朋友可以參考下
    2023-11-11
  • vue中輪訓(xùn)器的使用

    vue中輪訓(xùn)器的使用

    今天小編就為大家分享一篇關(guān)于vue中輪訓(xùn)器的使用,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • vue-cli中的webpack配置詳解

    vue-cli中的webpack配置詳解

    本篇文章主要介紹了vue-cli中的webpack配置詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • vue接入騰訊防水墻代碼

    vue接入騰訊防水墻代碼

    這篇文章主要介紹了vue接入騰訊防水墻代碼,代碼超級簡單,非常不錯,具有一定的參考借鑒價值 ,需要的朋友可以參考下
    2019-05-05
  • 解決vue移動端適配問題

    解決vue移動端適配問題

    這篇文章主要介紹了解決vue移動端適配問題,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • vue $router和$route的區(qū)別詳解

    vue $router和$route的區(qū)別詳解

    這篇文章主要介紹了vue $router和$route的區(qū)別詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • vue中view-model雙向綁定基礎(chǔ)原理解析

    vue中view-model雙向綁定基礎(chǔ)原理解析

    這篇文章主要介紹了vue中view-model雙向綁定基礎(chǔ)原理,文中給大家介紹了vue雙向綁定的原理總結(jié),本文通過示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-10-10
  • mpvue中使用flyjs全局?jǐn)r截的實現(xiàn)代碼

    mpvue中使用flyjs全局?jǐn)r截的實現(xiàn)代碼

    這篇文章主要介紹了mpvue中使用flyjs全局?jǐn)r截的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09
  • 在vue-cli腳手架中配置一個vue-router前端路由

    在vue-cli腳手架中配置一個vue-router前端路由

    這篇文章主要給大家介紹了在vue-cli腳手架中配置一個vue-router前端路由的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。
    2017-07-07
  • Nuxt封裝@nuxtjs/axios請求后端數(shù)據(jù)方式

    Nuxt封裝@nuxtjs/axios請求后端數(shù)據(jù)方式

    這篇文章主要介紹了Nuxt封裝@nuxtjs/axios請求后端數(shù)據(jù)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10

最新評論