我嘗試創建待辦事項列表旁邊的特點:使用summernote與vuejs
- 排序項
- 所見即所得的編輯器中的每個項目
- 在待辦事項模型中的每個變化項目的編輯店
我做了1和2,但不能做3.我只能改變任務列表中第一個任務的標題
Th是是我的代碼
app.js
Vue.directive('summernote', {
bind: function() {
this.editor = $(this.el).summernote({
airMode: true,
disableDragAndDrop: true,
popover: {
air: [
['style', ['bold', 'italic', 'underline', 'clear']]
]
},
callbacks: {
onChange: function(contents, $editable) {
vm.tasks[0].title = contents;
}
}
});
}
});
var vm = new Vue({
el: '#todos',
ready: function (value) {
Sortable.create(this.$el.firstChild, {
draggable: 'li',
animation: 500,
onUpdate: function(e) {
var oldPosition = e.item.getAttribute('data-id');
var newPosition = this.toArray().indexOf(oldPosition);
vm.tasks.splice(newPosition, 0, vm.tasks.splice(oldPosition, 1)[0]);
}
});
},
data: {
tasks: [
{ title: 'First task', done: true },
{ title: 'Second task', done: true },
{ title: 'Third task', done: false }
],
newTask: '',
editTask: null
},
methods: {
addTask (e) {
e.preventDefault();
this.tasks.push({ title: this.newTask, done: false });
this.newTask = '';
},
removeTask (index) {
this.tasks.splice(index, 1);
}
}
})
的index.html
<div class="container">
<div id="todos"><ul class="list-group">
<li
v-for="task in tasks"
class="list-group-item"
data-id="{{$index}}"
>
<span
@click="task.done = !task.done"
class="glyphicon glyphicon-ok"
></span>
<div v-summernote>{{ task.title }}</div>
<span @click="removeTask($index)" class="close">×</span>
</li>
</ul>
<form @submit="addTask">
<input v-model="newTask" class="form-control" type="text" placeholder="Add some task">
</form>
<div v-summernote></div>
<pre>{{tasks | json}}</pre>
<pre>{{editor}}</pre>
</div>
</div>
我如何可以編輯和保存在每個項目summernote的內容?這是工作example
'vm.tasks [0] .title僞=內容;'這是你拯救了什麼,對不對?你需要當前的任務。 –
是的,我想動態地獲取索引而不是[0]。我不能得到那個索引 –
我認爲你需要一個組件,看看https://github.com/Haixing-Hu/vue-html-editor –