(vue)draggable的使用:

该博客介绍了如何在 Vue.js 应用中利用 draggable 组件实现元素的拖拽操作,并展示了如何结合关闭按钮动态管理组件。通过设置 v-model、item-key 和 disabled 属性,以及运用 v-for 循环渲染子组件,并在 goClose 方法中删除对应项,实现了拖拽禁用和板块关闭的功能。样式部分定义了网格布局和关闭按钮的样式,使得拖拽元素具有良好的视觉效果。
摘要由CSDN通过智能技术生成

(vue)draggable的使用:

// 1.html
 <draggable
   v-if="flag"
   v-model="gridLists"
   class="grid-container"
   item-key="grid"
   animation="300"
   chosenClass="chosen"
   forceFallback="true"
   disabled="true"  // 禁止拖拽
 >
   <div class="line" v-for="(item, index) in gridLists" :key="index">
     <div :is="item.component"></div> // 组件内容
     <span class="el-icon-close" @click="goClose(item.num)"></span>  // 关闭按钮
   </div>
 </draggable>
 
// 2.引入子组件
	import HotSearch from "@/components/Intelligence/search/HotSearch";
	import Trend from "@/components/Intelligence/search/Trend";

// 3.子组件数组
  data() {
    return { 
      gridLists: [
        { grid: "cn", num: 1, component: HotSearch },
        { grid: "cn", num: 2, component: Trend },
      ],
    };
  },
  
// 4.方法
// 板块关闭
goClose(num) {
  this.gridLists.forEach((item, index) => {
    if (item.num == num) {
      this.gridLists.splice(index, 1);
    }
  });
},

效果 :
在这里插入图片描述

// 5.样式
  .grid-container {
    width: 100%;
    height: 86vh;
    display: grid;
    grid-template-columns: 33.3% 33.3% 33.3%;
    grid-template-rows: 33.3% 33.3% 33.3%;
  }
  .line {
    position: relative;
    font-size: 2em;
    cursor: pointer;
    height: 560px;
    background-color: rgb(242, 242, 242);
    margin-right: 10px;
    margin-bottom: 10px;
  }
  // 关闭按钮
  .close {
    width: 50px;
    height: 50px;
  }
  .el-icon-close {
    position: absolute;
    right: 10px;
    top: 10px;
    cursor: pointer;
    font-size: 20px;
  }
  .el-icon-close:before {
    position: absolute;
    content: "";
    width: 2px;
    height: 20px;
    background: blue;
    transform: rotate(45deg);
    top: -3px;
    left: -11px;
  }
  .el-icon-close:after {
    content: "";
    position: absolute;
    width: 2px;
    height: 20px;
    background: blue;
    transform: rotate(-45deg);
    top: -3px;
    left: -11px;
  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值