我是Vuejs和vuetify的新手,也是stackoverflow的新手。我的任务是在vuetify中制作一个可拖动的扩展面板。我尝试了很多,但没有任何结果。这是我遵循的一些小提琴和github源代码:
1。)https://github.com/SortableJS/Vue.Draggable
2。)Functionnal Vuejs 2可排序的v-展开面板-请使用Google搜索
但是对我来说没有任何结果。有人可以帮我这个忙吗?我可以参考的小提琴或小提琴吗?
我无法仅通过cdn导入使用此vuetify和vue.js的组件。
非常感谢您的帮助。
HTML(原型):
<div id="app">
<v-app id="inspire">
<v-data-table
v-bind:headers="headers"
:items="items"
hide-actions
class="elevation-1"
ref="sortableTable"
>
<template slot="items" slot-scope="props">
<tr class="sortableRow" :key="itemKey(props.item)"> <!-- NOTE: You'll need a unique ID, that is specific to the given item, for the key. Not providing a unique key that's bound to the item object will break drag and drop sorting. The itemKey method will return a uid for a given object using WeakMap. You could just use a property in the object with a unique value, like "props.item.name" in this case, but often getting a unique value from the object's properties can be difficult, like when adding new rows, or when the unique field is open to editing, etc. -->
<td class="px-1" style="width: 0.1%">
<v-btn style="cursor: move" icon class="sortHandle"><v-icon>drag_handle</v-icon></v-btn>
</td>
<td>{{ props.item.name }}</td>
<td class="text-xs-right">{{ props.item.calories }}</td>
<td class="text-xs-right">{{ props.item.fat }}</td>
<td class="text-xs-right">{{ props.item.carbs }}</td>
<td class="text-xs-right">{{ props.item.protein }}</td>
<td class="text-xs-right">{{ props.item.sodium }}</td>
<td class="text-xs-right">{{ props.item.calcium }}</td>
<td class="text-xs-right">{{ props.item.iron }}</td>
</tr>
</template>
</v-data-table>
</v-app>
</div>
JS原型:
new Vue({
el: '#app',
mounted () {
/* eslint-disable no-new */
new Sortable(
this.$refs.sortableTable.$el.getElementsByTagName('tbody')[0],
{
draggable: '.sortableRow',
handle: '.sortHandle',
onEnd: this.dragReorder
}
)
},
methods: {
dragReorder ({oldIndex, newIndex}) {
const movedItem = this.items.splice(oldIndex, 1)[0]
this.items.splice(newIndex, 0, movedItem)
},
itemKey (item) {
if (!this.itemKeys.has(item)) this.itemKeys.set(item, ++this.currentItemKey)
return this.itemKeys.get(item)
}
},
data () {
return {
itemKeys: new WeakMap(),
currentItemKey: 0,
headers: [
{
sortable: false
},
{
text: 'Dessert (100g serving)',
align: 'left',
sortable: false,
value: 'name'
},
{ text: 'Calories', value: 'calories', sortable: false },
{ text: 'Fat (g)', value: 'fat', sortable: false },
{ text: 'Carbs (g)', value: 'carbs', sortable: false },
{ text: 'Protein (g)', value: 'protein', sortable: false },
{ text: 'Sodium (mg)', value: 'sodium', sortable: false },
{ text: 'Calcium (%)', value: 'calcium', sortable: false },
{ text: 'Iron (%)', value: 'iron', sortable: false }
],
items: [
{
value: false,
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
sodium: 87,
calcium: '14%',
iron: '1%'
},
{
value: false,
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
sodium: 129,
calcium: '8%',
iron: '1%'
},
{
value: false,
name: 'Eclair',
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
sodium: 337,
calcium: '6%',
iron: '7%'
},
{
value: false,
name: 'Cupcake',
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
sodium: 413,
calcium: '3%',
iron: '8%'
},
{
value: false,
name: 'Gingerbread',
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
sodium: 327,
calcium: '7%',
iron: '16%'
},
{
value: false,
name: 'Jelly bean',
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
sodium: 50,
calcium: '0%',
iron: '0%'
},
{
value: false,
name: 'Lollipop',
calories: 392,
fat: 0.2,
carbs: 98,
protein: 0,
sodium: 38,
calcium: '0%',
iron: '2%'
},
{
value: false,
name: 'Honeycomb',
calories: 408,
fat: 3.2,
carbs: 87,
protein: 6.5,
sodium: 562,
calcium: '0%',
iron: '45%'
},
{
value: false,
name: 'Donut',
calories: 452,
fat: 25.0,
carbs: 51,
protein: 4.9,
sodium: 326,
calcium: '2%',
iron: '22%'
},
{
value: false,
name: 'KitKat',
calories: 518,
fat: 26.0,
carbs: 65,
protein: 7,
sodium: 54,
calcium: '12%',
iron: '6%'
}
]
}
}
})