【发布时间】:2018-01-23 12:17:21
【问题描述】:
我需要在表 #dynamic 中添加行,但表 static 不应该受到影响。
如果我点击下面代码的按钮,两个表都会更新,因为它们有相同的v-for。而且,如果我将v-for 放入v-for,我的数据将不会被获取。我不知道如何“唯一”第一个表。
vue/html:
<template>
<table id="dynamic">
<tr v-for="rows in list">
<td>Content of row {{ rows.item1 }}</td>
<td>Content of row {{ rows.item2 }}</td>
</tr>
</table>
<div @click="block = !block">click</div>
<table id="static">
<tr v-for="rows in list">
<td>Content of row: {{ rows.item3 }}</td>
<td>Content of row: {{ rows.item4 }}</td>
</tr>
</table>
</template>
js
export default {
data: function () {
return {
list: [],
};
},
props: ['channelId'],
mounted() { },
created() {
this.fetchChannel(this.channelId);
},
methods: {
fetchChannel: function (channelId) {
$.getJSON('/api/channel/' + channelId, function (data) {
this.list = data;
}.bind(this));
},
}
}
我找到了一些帮助示例,例如 this codepen 或 fiddle,但我没有成功。
【问题讨论】:
标签: javascript html json for-loop vue.js