注意: Edit/update使用SPA(不换页)的方法完成。点击文字出现一个输入框和按钮。
我的git: https://github.com/chentianwei411/vue-lists
addLine: function() {
this.$http.post(‘/lists.json‘, { item: this.checkInput }, {}).then(response => {
this.fetchLists(), this.checkInput = ‘‘
}).catch(function(error) {
console.log(‘Got a problem‘ + error)
})
}
catch用于全程出错后,对错误的处理。
deleteLine(id) {
this.$http.delete(`/lists/${id}.json`).then(response => {
this.fetchLists()
})
当true时,元素不能用。包括<button><input><select><textarea><options>
<input type=‘text‘ v-model=‘line‘ class=‘form-control‘ autofocus="true">
<button v-on:click=‘addLine()‘ class=‘btn btn-primary‘ :disabled="!line.length" >Add line</button>
line是string。调用!line.length方法, 结果有2种:
例子:
var persons = [
{firstname : "Malcom", lastname: "Reynolds"},
{firstname : "Kaylee", lastname: "Frye"},
{firstname : "Jayne", lastname: "Cobb"}
];
persons.map((old) => { old.secondname = ‘hello‘; return old})
结果
[
{firstname: "Malcom", lastname: "Reynolds", secondname: "hello"},
{firstname: "Kaylee", lastname: "Frye", secondname: "hello"},
{firstname: "Jayne", lastname: "Cobb", secondname: "hello"}
]
arr.map(function(old) { return new })
用Rails.5.2+ Vue.js做 vue-todolist app
原文:https://www.cnblogs.com/chentianwei/p/9645913.html