我有一个名为"sortable"的自定义指令,但我遇到了DOM的问题.问题是当我拖放项目时,数组被更改但DOM不是.
这是我的自定义指令:
Vue.directive('sortable', {
bind: function(el, binding, vnode) {
// Initialize sortable
this.sortable = Sortable.create(el, {});
console.debug("Sortable initialized");
this.sortable.option("onUpdate", function(event) {
binding.value.move(event.oldIndex, event.newIndex);
var updated = binding.value;
Vue.set(tasks, updated);
});
}
});
Run Code Online (Sandbox Code Playgroud)
这就是我创建Vue实例的方法:
app = new Vue({
el: "#app",
data: {
subtotal: 0,
tasks: [
{name: '', quantity: '', rate: 80, costs: ''}
]
},
methods: {
newTask: function() {
this.tasks.push({name: '', quantity: '', rate: 80, costs: ''})
},
deleteTask: function(index) {
this.tasks.splice(index, 1);
this.calculateTotal();
},
calculateCosts: function(event, value, index) …Run Code Online (Sandbox Code Playgroud)