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

利用Vue-draggable組件實(shí)現(xiàn)Vue項(xiàng)目中表格內(nèi)容的拖拽排序

 更新時(shí)間:2019年06月07日 09:12:28   作者:青橙618  
這篇文章主要介紹了利用Vue-draggable組件實(shí)現(xiàn)Vue項(xiàng)目中表格內(nèi)容的拖拽排序,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

Vue-draggable 的github傳送門 :

https://github.com/SortableJS/Vue.Draggable

一. 下載依賴包:npm install vuedraggable -S 

二. 在需要使用的當(dāng)前界面引入依賴,注冊組件:

import draggable from "vuedraggable";
export default {
 components: {
 draggable,
 } 

三. 在template 中建立表格,分別寫出thead 部分不變, 此處需要將draggable 渲染成tbody,不然draggable會(huì)被解析成div 影響樣式。

(渲染方法:<draggable v-model="tablelist" element="tbody">)

<table class="dataTabble">
 <thead>
 <tr>
  <th width="110">欄目名稱</th>
  <th width="200">發(fā)布時(shí)間</th>
  <th width="160">公告數(shù)量</th>
  <th width="160">操作</th>
 </tr>
 </thead>
 <draggable v-model="tablelist" element="tbody" :move="getdata" @update="datadragEnd">
 <tr v-for="(item,id) in tablelist" :key="id">
  <td>{{item.name}}</td>
  <td>{{item.time}}</td>
  <td>{{item.num}}</td>
  <td>
  <div class="tabopa">
   <a @click="dialogFormVisible = true" style="cursor:pointer">添加</a>
   <a @click="open2">刪除</a>
  </div>
  </td>
 </tr>
 </draggable>
</table>
<div class="zhu mt40">提示:拖動(dòng)可對欄目進(jìn)行排序</div> 

此處data部分,通過{ {   } } 獲取data中數(shù)據(jù),實(shí)際中通過請求獲取

data() {
 return {
 tablelist: [
  { id: 1, name: "活動(dòng)消息1", time: "2018-08-25 14:54", num: "1000" },
  { id: 2, name: "公司消息2", time: "2018-08-25 14:54", num: "200" },
  { id: 3, name: "個(gè)人消息3", time: "2018-08-25 14:54", num: "30000" },
  { id: 4, name: "客戶消息4", time: "2018-08-25 14:54", num: "40" }
 ],
 };
}, 

四.相關(guān)方法

獲取拖動(dòng)中和拖動(dòng)結(jié)束時(shí)的id

methods: {
 //拖動(dòng)中與拖動(dòng)結(jié)束
 getdata(evt) {
  console.log(evt.draggedContext.element.id);
 },
 datadragEnd(evt) {
  console.log("拖動(dòng)前的索引 :" + evt.oldIndex);
  console.log("拖動(dòng)后的索引 :" + evt.newIndex);
  console.log(this.tags);
 }, 

 五.貼出全部代碼

<template>
 <div>
 <!--main-->
   <table class="dataTabble">
    <thead>
    <tr>
     <th width="110">欄目名稱</th>
     <th width="200">發(fā)布時(shí)間</th>
     <th width="160">公告數(shù)量</th>
     <th width="160">操作</th>
    </tr>
    </thead>
    <draggable v-model="tablelist" element="tbody" :move="getdata" @update="datadragEnd">
    <tr v-for="(item,id) in tablelist" :key="id">
     <td>{{item.name}}</td>
     <td>{{item.time}}</td>
     <td>{{item.num}}</td>
     <td>
     <div class="tabopa">
      <a @click="dialogFormVisible = true" style="cursor:pointer">添加</a>
      <a @click="open2">刪除</a>
     </div>
     </td>
    </tr>
    </draggable>
   </table>
   <div class="zhu mt40">提示:拖動(dòng)可對欄目進(jìn)行排序</div>
 <!--main end-->
 </div>
</template>
<script>
import draggable from "vuedraggable";
export default {
 components: {
 draggable,
 },
 data() {
 return {
  tablelist: [
  { id: 1, name: "活動(dòng)消息1", time: "2018-08-25 14:54", num: "1000" },
  { id: 2, name: "公司消息2", time: "2018-08-25 14:54", num: "200" },
  { id: 3, name: "個(gè)人消息3", time: "2018-08-25 14:54", num: "30000" },
  { id: 4, name: "客戶消息4", time: "2018-08-25 14:54", num: "40" }
  ],
 };
 },
 methods: {
 //拖動(dòng)中與拖動(dòng)結(jié)束
 getdata(evt) {
  console.log(evt.draggedContext.element.id);
 },
 datadragEnd(evt) {
  console.log("拖動(dòng)前的索引 :" + evt.oldIndex);
  console.log("拖動(dòng)后的索引 :" + evt.newIndex);
  console.log(this.tags);
 },
 }
}
</script>
<style>
</style> 

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

  • 詳解vue-cli項(xiàng)目開發(fā)/生產(chǎn)環(huán)境代理實(shí)現(xiàn)跨域請求

    詳解vue-cli項(xiàng)目開發(fā)/生產(chǎn)環(huán)境代理實(shí)現(xiàn)跨域請求

    這篇文章主要介紹了詳解vue-cli項(xiàng)目開發(fā)/生產(chǎn)環(huán)境代理實(shí)現(xiàn)跨域請求,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • vue中用動(dòng)態(tài)組件實(shí)現(xiàn)選項(xiàng)卡切換效果

    vue中用動(dòng)態(tài)組件實(shí)現(xiàn)選項(xiàng)卡切換效果

    本篇文章主要介紹了vue中用動(dòng)態(tài)組件實(shí)現(xiàn)選項(xiàng)卡切換效果,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-03-03
  • Vue3 Vant組件庫使用過程中的避坑點(diǎn)

    Vue3 Vant組件庫使用過程中的避坑點(diǎn)

    本片文章主要寫了,Vue3開發(fā)時(shí)運(yùn)用Vant UI庫的一些避坑點(diǎn)。讓有問題的小伙伴可以快速了解是為什么。也是給自己做一個(gè)記錄
    2023-04-04
  • 詳解Vue-cli3 項(xiàng)目在安卓低版本系統(tǒng)和IE上白屏問題解決

    詳解Vue-cli3 項(xiàng)目在安卓低版本系統(tǒng)和IE上白屏問題解決

    這篇文章主要介紹了Vue-cli3 項(xiàng)目在安卓低版本系統(tǒng)和 IE 上白屏問題解決,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-04-04
  • vue-cli 構(gòu)建骨架屏的方法示例

    vue-cli 構(gòu)建骨架屏的方法示例

    這篇文章主要介紹了vue-cli 構(gòu)建骨架屏的方法示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-11-11
  • Vue中addEventListener()?監(jiān)聽事件案例講解

    Vue中addEventListener()?監(jiān)聽事件案例講解

    這篇文章主要介紹了Vue中addEventListener()?監(jiān)聽事件案例講解,包括語法講解和事件冒泡或事件捕獲的相關(guān)知識(shí),本文結(jié)合示例代碼給大家講解的非常詳細(xì),需要的朋友可以參考下
    2022-12-12
  • vue 項(xiàng)目代碼拆分的方案

    vue 項(xiàng)目代碼拆分的方案

    這篇文章主要介紹了vue 項(xiàng)目代碼拆分的方案,幫助大家更好的理解和學(xué)習(xí)使用vue框架,感興趣的朋友可以了解下
    2021-03-03
  • 淺析Vue如何巧用computed計(jì)算屬性

    淺析Vue如何巧用computed計(jì)算屬性

    在日常使用Vue開發(fā)項(xiàng)目的時(shí)候,計(jì)算屬性computed是一個(gè)非常常用的特性,本文就來分享一些使用Vue的computed計(jì)算屬性時(shí)的一些小技巧,希望能夠幫助到大家
    2023-06-06
  • Vue頁面堆棧管理器詳情

    Vue頁面堆棧管理器詳情

    這篇文章主要介紹了Vue頁面堆棧管理器
    2021-10-10
  • 最新評論