vue Draggable實現(xiàn)拖動改變順序
更新時間:2022年04月07日 08:04:02 作者:懶怪
這篇文章主要為大家詳細介紹了vue Draggable實現(xiàn)拖動改變順序,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue Draggable實現(xiàn)拖動改變順序的具體代碼,供大家參考,具體內(nèi)容如下
1、npm install vuedraggable
2、import draggable from 'vuedraggable'
3、示例代碼
Test.vue
<template>
?<ul class="sort-ul">
? ? <div>45454</div>
? ? <draggable ?group="article" :value="sortArr" @input="handleListChange($event)">
? ? ? ?<li v-for="(item,index) in sortArr" :key="index">
? ? ? ? ?<h2>{{item.title}}</h2>
? ? ? ?</li>
? ? </draggable>
? </ul>
</template>
<script>
import Draggable from 'vuedraggable';
export default {
? name: 'Test',
? props:{
? },
? data () {
? ? return {
? ? ? fileList: [],
? ? ? sortArr:[
? ? ? ? {title:"00"},
? ? ? ? {title:"01"},
? ? ? ? {title:"02"},
? ? ? ? {title:"03"},
? ? ? ? {title:"04"},
? ? ? ? {title:"05"},
? ? ? ? {title:"06"},
? ? ? ? {title:"07"},
? ? ? ? {title:"08"},
? ? ? ? {title:"09"},
? ? ? ],
? ? }
? },
? components: {
? ? Draggable, ?
? },
? methods: {
? ? ? // 更新位置
? ? ? handleListChange(event){
? ? ? ? console.log(event);
? ? ? ? this.sortArr = event;
? ? ? }
? },
? mounted () {
? ?
? }
}
</script>
<style>
? ul{
? ? padding: 0;
? ? width: 400px;
? }
? li{
? ? width: 100px;
? ? float:left;
? }
</style>main.js
import Vue from 'vue'
import App from './App'
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
? ? el: '#app',
? ? components: { App },
? ? template: '<App/>'
})app.vue
<template>
? <div id="app">
? ? <Test />
? </div>
</template>
<script>
import Test from '@/components/Test.vue'
export default {
? name: 'App',
? components:{
? ? Test,
? },
? methods: {
? }
}
</script>以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關文章
vue-router跳轉(zhuǎn)時打開新頁面的兩種方法
這篇文章主要給大家介紹了關于vue-router跳轉(zhuǎn)時打開新頁面的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用vue-router具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-07-07
Vue2安裝使用MonacoEditor方式(自定義語法,自定義高亮,自定義提示)
這篇文章主要介紹了Vue2安裝使用MonacoEditor方式(自定義語法,自定義高亮,自定義提示),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04

