vue.js - How to integrate Vue.Draggable into my components -
i'm trying integrate vue.draggable project https://github.com/sortablejs/vue.draggable
i'm little confused how integrate existing project vue.draggable. want every element created in v-for loop draggable. i'm used using jquery ui achieve this, want vue-centric approach.
what best way this?
var height = $(document).height(); var width = $(document).width(); $(function() { vue.component('sidebar', { data: () => { return { people: [] } }, template: ` <div id="sidebar"> <div v-for="person in people" :class="[{'checked-in': ischeckedin(person)}, 'person']" :id="person.id"> {{person.first_name + ' ' + person.last_name}} </div> </div> `, methods: { ischeckedin(person) { return person.reg_scan == null ? true : false; }, loadpeople() { $.ajax({ method: 'post', datatype: 'json', url: base_url + 'users/getparticipants/' + event_id }).done(data => { this.people = data; }); } }, mounted() { this.loadpeople(); setinterval(() => { console.log("getting people"); this.loadpeople(); }, 10000); } }); vue.component('tables', { data: () => { return { tables: [] } }, template: ` <div id="tables"> <div class='table' v-for="table in tables" :style="computeoffsets(table)"> {{table.name}} </div> </div> `, methods: { loadtables() { $.ajax({ method: 'post', datatype: 'json', url: base_url + 'tables/gettables/' + event_id }).done(data => { this.tables = data; }); }, computeoffsets(table) { return { top: (table.position_x * width) + 'px', left: (table.position_y * height) + 'px' } } }, mounted() { this.loadtables(); setinterval(() => { console.log("getting tables"); this.loadtables(); }, 10000); } }); var app = new vue({ el: '#main' }); });
.table { position: absolute; } #sidebar { width: 10%; float: left; height: 500px; overflow-y: scroll; } .checked-in { background-color: lightgreen; }
<head> <script src="//cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/sortable/1.6.0/sortable.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/vue.draggable/2.14.1/vuedraggable.min.js"></script> </head> <div id="main"> <sidebar></sidebar> <tables></tables> </div>
change:
<div id="sidebar"> <div v-for="person in people" :class="[{'checked-in': ischeckedin(person)}, 'person']" :id="person.id"> {{person.first_name + ' ' + person.last_name}} </div> </div>
to:
<draggable> <div v-for="person in people" :class="[{'checked-in': ischeckedin(person)}, 'person']" :id="person.id"> {{person.first_name + ' ' + person.last_name}} </div> </draggable >
Comments
Post a Comment