首页 > 其他分享 >vue3+ts利用draggable组件实现拖拽

vue3+ts利用draggable组件实现拖拽

时间:2023-07-21 16:36:06浏览次数:27  
标签:name ts id draggable drag vue3 组件 border 拖拽

界面展示

实现步骤
npm i -S vuedraggable@next
  • 引入并使用组件
<template>
    <!-- 此页面template中没有可刷新页面的数据变化,拖拽会不起作用,所以加个activeInfo来使界面刷新 -->
    {{ activeInfo }}
    <Draggable class="drag_box" v-model="myArray" group="people" @start="changeDrag(true)" @end="changeDrag(false)" item-key="id">
        <template #item="{ element }">
            <div class="drag_item">{{ element.id }} —— {{ element.name }}</div>
        </template>
    </Draggable>
</template>
 
<script lang="ts" setup>
import { reactive, ref, computed } from 'vue'
import Draggable from 'vuedraggable'
let drag = ref<boolean>(false)
interface iUser {
    id: number,
    name: string,
}
let myArray = reactive<iUser[]>([
    { id: 1, name: '张三' },
    { id: 2, name: '李四' },
    { id: 3, name: '孙五' }
])
let activeInfo = computed({
    get() {
        return drag.value ? '正在拖拽中...' : '没有拖拽!!';
    },
    set() { }
});
const changeDrag = function (val: boolean) {
    drag.value = val
    console.log(drag.value)
}
</script>
<style scoped>
.drag_box {
    width: 200px;
    border-radius: 6px;
    border: 2px solid #ccc;
    padding: 0 10px;
}

.drag_item {
    border-radius: 6px;
    border: 2px solid salmon;
    margin: 10px 0;
    padding: 5px;
}
</style>
存疑未解决 在此页面中,如果template中显示仅仅只有Draggable组件,会存在组件拖拽不生效(会发现拖拽事件changeDrag是执行了,但是页面没有刷新)。

标签:name,ts,id,draggable,drag,vue3,组件,border,拖拽
From: https://www.cnblogs.com/nicoz/p/17571772.html

相关文章

  • vue3组合式 API_为 computed() 标注类型
    computed() 会自动从其计算函数的返回值上推导出类型<template><h3>{{doubleCount}}</h3></template><scriptsetuplang="ts">import{ref,computed}from"vue"constcount=ref<number>(100)//推导得到的类型:ComputedRef&l......
  • [LeetCode] 1349. Maximum Students Taking Exam 参加考试的最大学生数
    Givena m *n matrix seats  thatrepresentseatsdistributions inaclassroom. Ifaseat is broken,itisdenotedby '#' characterotherwiseitisdenotedbya '.' character.Studentscanseetheanswersofthosesittingnexttothele......
  • springboot学习之十三(druid+mybaits plus)
    Druid介绍Druid是阿里巴巴的一个开源项目,号称为监控而生的数据库连接池,在功能、性能、扩展性方面都超过其他例如DBCP、C3P0、BoneCP、Proxool、JBossDataSource等连接池,而且Druid已经在阿里巴巴部署了超过600个应用,通过了极为严格的考验,这才收获了大家的青睐! Springboot集成......
  • DataArts Studio实践丨通过Rest Client 接口读取RESTful接口数据的能力
    本文分享自华为云社区《DataArtsStudio通过RestClient接口读取RESTful接口数据的能力,通过Hive-SQL存储》,作者:张浩奇。RestClient提供了读取RESTful接口数据的能力。RestClient从RESTful地址中获取数据,转换为数据集成支持的数据类型,然后传递给下游的hive-sql节点存储。本文......
  • vue3中组合式 API_为 reactive() 标注类型
    reactive() 也会隐式地从它的参数中推导类型<template><h3>{{book.title}}</h3><h3>{{book.author}}</h3></template><scriptsetuplang="ts">import{reactive}from"vue"constbook=reactive({title......
  • Vue3 响应式全局对象json 动态绑定界面三 (Div块样式 字符串叠加)
    效果 man.js  定义响应式全局对象 globalData//全局对象constglobalData=reactive({missedCallData:"",currentUserTel:"",})app.provide('globalData',globalData);在main.js的函数中改变missedCallData 的值从而改变界面列表//改变全局变量gl......
  • Vue3 响应式全局对象json 动态绑定界面四 (Div块样式 Json数据绑定)
    效果man.js  定义响应式全局对象 globalData//全局对象constglobalData=reactive({extTelTalkData:[{userExten:"1000",userName:"刘亦菲",callStatus:"通话"},{......
  • python得Requests
    Python的Requests库介绍与使用1.引言在Python中,我们经常需要发送HTTP请求,以获取远程服务器上的数据或者与其进行交互。Python的Requests库是一个非常强大且易于使用的HTTP库,可以简化HTTP请求的发送过程。本文将介绍Requests库的基本用法和一些高级功能,帮助你快速上手使用Request......
  • Vue3 响应式全局对象json 动态绑定界面二 (方块矩阵样式)
    效果main.js//全局对象constglobalData=reactive({extTelMonitorData:[{title:'用户组一',list:[{groupID:"0",groupName:"AllUsers",......
  • CTS测试
    镜像文件镜像文件与安全补丁securtiypatch的月份对应#CTS-on-GSIadbrebootbootloaderfastbootflashingunlockfastbootflashingunlock_criticalfastbootrebootfastbootfastbootflashsystemsystem.imgfastboot-wfastbootreboot#VTSadbrebootbootloade......