【发布时间】:2018-08-20 08:07:23
【问题描述】:
我的 HTML 代码:
<div id="app">
<table>
<thead>
<tr>
<th>#</th>
<th>title</th>
<th>price</th>
</tr>
</thead>
<tbody>
<tr v-for="wage_definition in wage_definitions" :key="wage_definition.id">
<td>{{ wage_definition.id }}</td>
<td>{{ wage_definition.definition_title }}</td>
<td>
<input type="text" name="amount" @change="valueChanged(wage_definition)"
v-model.lazy="wage_definition.amount">
<button v-if="wage_definition.changed" class="btn btn-sm btn-success"
@click="update(wage_definition)">save change
</button>
<span v-if="wage_definition.updated" class="label label-success">updated</span>
</td>
</tr>
</tbody>
</table>
而我的js代码是:
var app = new Vue({
el: '#app',
data: {
wage_definitions: [{
"id": 1,
"definition_title": "first",
"amount": 151,
"created_at": null,
"updated_at": "2018-03-12 14:34:27"
}, {
"id": 2,
"definition_title": "second",
"amount": 152,
"created_at": null,
"updated_at": "2018-03-12 14:34:34"
}, {
"id": 3,
"definition_title": "another record",
"amount": 0,
"created_at": null,
"updated_at": null
}, {
"id": 4,
"definition_title": "hello",
"amount": 0,
"created_at": null,
"updated_at": null
}, {
"id": 5,
"definition_title": "world",
"amount": 0,
"created_at": null,
"updated_at": null
}, {
"id": 6,
"definition_title": "foo bar",
"amount": 0,
"created_at": null,
"updated_at": null
}]
},
methods: {
valueChanged: function (wage_definition) {
wage_definition.changed = true;
wage_definition.updated = false;
},
update: function (wage_definition) {
wage_definition.changed = false;
wage_definition.updated = true;
}
}
});
在我更改输入值后,将显示“保存更改”按钮,但是当我单击“保存更改”按钮时,“更新”警报不会立即显示。 我必须更改另一个字段,然后显示“更新”警报。
我怎样才能马上做到?
这里是 jsfiddle 链接: https://jsfiddle.net/5qupbc3w/1/
【问题讨论】:
-
呃……你为什么把它命名为
vue?你知道 Vue 使用它吗? -
JavaScript 是一种区分大小写的语言。我觉得不重要
-
你没有在听。 Vue 使用
vue变量... -
我把它重命名为 app.但是这个问题没有解决。
标签: javascript php laravel vue.js