# 一级导航拖拽/二级拖拽

# 快速导航

# 背景

在一些后台管理系统里,有时候需要一级拖拽排序,甚至二级拖拽排序

# 实例效果

自然风景(4)
城市风光(5)
蓝天白云(6)
浪漫大海(7)
幽静森林(8)

# 具体实现

实例代码如下所示
<template>
    <div class="tag-relation-wrap">
         <div class="tag-tab">
            <ul class="tag-tab-ul">
              <draggable v-model="firstTabLists" animation="1000">
                 <transition-group> 
                    <li v-for="(item) in firstTabLists" 
                        :key="item.id" 
                        class="tab-ul-li"
                        :class="{selectTab:curTab==item.id}" 
                        @click="handleLevel1TagLi(item.id)"
                    >
                        {{item.title}}
                    </li>
                 </transition-group>   
              </draggable>  
            </ul>
            <div class="second-tag-content">
                  <draggable v-model="secondTagLists" class="draggable" @start="handleOnStart" @end="handleOnEnd" animation="1000">
                    <transition-group>
                        <div class="second-tag-list" v-for="(item) in secondTagLists" :key="item.id">
                          <div v-if="curTab == item.parent.id">
                              <div>
                                 <img :src="item.logo" width="150" height="100" style="margin-right:10px;" alt="">
                              </div>
                              <div>{{item.title}}({{item.img_count}})</div>
                          </div>
                        </div>
                    </transition-group>  
                  </draggable> 
                  
            </div>
         </div>
    </div>
</template>

<script>
import draggable from 'vuedraggable'
    export default {
        name: 'levelDraw',
        components: {
            draggable
        },
        data() {
            return {
                curTab: 0,
                drag: false,
                firstTabLists: [],
                secondTagLists: [
                    {
                        id: "111",
                        logo: "https://t7.baidu.com/it/u=2604797219,1573897854&fm=193&f=GIF",
                        title: "自然风景",
                        img_count: "4",
                        parent: {
                            id: "0"
                        }
                    },
                    {
                        id: "112",
                        logo: "https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00607-2747.jpg",
                        title: "城市风光",
                        img_count: "5",
                        parent: {
                            id: "0",
                        }
                    },

                     {
                        id: "113",
                        logo: "https://img1.baidu.com/it/u=3359541483,3941166536&fm=26&fmt=auto",
                        title: "蓝天白云",
                        img_count: "6",
                        parent: {
                            id: "0",
                        }
                    },

                    {
                        id: "114",
                        logo: "https://img2.baidu.com/it/u=1986005730,948348151&fm=26&fmt=auto",
                        title: "浪漫大海",
                        img_count: "7",
                        parent: {
                            id: "0",
                        }
                    },

                    {
                        id: "115",
                        logo: "https://img1.baidu.com/it/u=4096324645,3052151476&fm=26&fmt=auto",
                        title: "幽静森林",
                        img_count: "8",
                        parent: {
                            id: "0",
                        }
                    },

                     {
                        id: "116",
                        logo: "https://img0.baidu.com/it/u=986567382,3731968355&fm=26&fmt=auto",
                        title: "风景",
                        img_count: "8",
                        parent: {
                            id: "1",
                        }
                    },
                    {
                        id: "117",
                        logo: "https://img2.baidu.com/it/u=3493136389,1353360279&fm=26&fmt=auto",
                        title: "人文",
                        img_count: "5",
                        parent: {
                            id: "1",
                        }
                    },

                    {
                        id: "118",
                        logo: "https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00237-960.jpg",
                        title: "植物",
                        img_count: "9",
                        parent: {
                            id: "1",
                        }
                    },

                     {
                        id: "119",
                        logo: "https://img1.baidu.com/it/u=3108395991,3014709597&fm=26&fmt=auto",
                        title: "动物",
                        img_count: "6",
                        parent: {
                            id: "1",
                        }
                    },

                     {
                        id: "120",
                        logo: "https://img2.baidu.com/it/u=2629675476,1507451532&fm=26&fmt=auto",
                        title: "绿色护眼",
                        img_count: "6",
                        parent: {
                            id: "2",
                        }
                    },

                     {
                        id: "121",
                        logo: "https://img1.baidu.com/it/u=2985957268,45475772&fm=26&fmt=auto",
                        title: "清新淡雅",
                        img_count: "6",
                        parent: {
                            id: "2",
                        }
                    },

                    {
                        id: "122",
                        logo: "https://img1.baidu.com/it/u=2433542901,3786348763&fm=15&fmt=auto",
                        title: "艺术作品",
                        img_count: "7",
                        parent: {
                            id: "3",
                        }
                    },

                     {
                        id: "123",
                        logo: "https://img0.baidu.com/it/u=3147964452,2678650339&fm=26&fmt=auto",
                        title: "二次元",
                        img_count: "8",
                        parent: {
                            id: "3",
                        }
                    },

                    {
                        id: "124",
                        logo: "https://img0.baidu.com/it/u=251703063,4193365027&fm=26&fmt=auto",
                        title: "打工人",
                        img_count: "8",
                        parent: {
                            id: "3",
                        }
                    }
                ],
            }
        },

        mounted() {
            this.mockFirstTabList();
            
        },

        

        methods: {
            handleLevel1TagLi(id) {
                console.log(id);
                this.curTab = id;

            },
            mockFirstTabList() {
                let firstLevelTitle = ["风景","摄影","花草","插画","影视","美女","汽车","简约"];
                for(let i = 0;i<=firstLevelTitle.length;i++) {
                    this.firstTabLists.push({
                        id: i,
                        title: firstLevelTitle[i]
                    })
                }
           },

            // 开始拖拽
            handleOnStart() {
                this.drag = true;
            },
            // 结束拖拽
            handleOnEnd() {
                this.drag = false;
            },
        }
    }
</script>

<style lang="scss" scoped>
.tag-relation-wrap {
  display: flex;
  justify-content: space-between;
  .tag-tab {
    flex: 1;
    margin-top: 20px;
    .second-tag-content {
       margin-top: 10px;
       .draggable {
         span {
            display: flex;
            flex-wrap: wrap;
            .second-tag-list {
              display:flex;
              flex-direction: column;
              align-items: center;
            //   margin-right: 10px;
              margin-bottom: 10px;
              cursor: move;
              text-align: center;
            }
         }
         
       }
      
    }

    .tag-tab-ul {
      display: flex;
      span{
        display: flex;
      }
      .tab-ul-li {
        margin-right: 25px;
      }
      .selectTab {
        color: #409EFF;
        cursor: move;
        border-bottom: 2px solid #409EFF;
      }
    }
  }
  /deep/ .el-tabs__nav-wrap::after {
    display:none;
  }
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273

温馨提示

这里的拖拽主要借助vuedraggable组件,实现tab切换,主要是根据一级导航与二级导航相关联的id,实现的一个切换

白色

关注公众号

一个走心,有温度的号,同千万同行一起交流学习

加作者微信

扫二维码 备注 【加群】

扫码易购

福利推荐