我有一个表行,是以表行的值,并将其放入一个列表,然后我设置列表等于VUE阵列我这里是阵列jQuery的点击功能。 阵列:Vue的数组不更新
tableRow: [
{
"name": "1",
"numSongs": "2",
"Year": "3"
}
]
功能:
$("#table1 tr").click(function() {
var list = [];
var $row = $(this).closest("tr"),
$tds = $row.find("td");
list.push({ name: $tds.eq(0).text(), numSongs: $tds.eq(1).text(), Year: $tds.eq(2).text() });
this.tableRow = list;
console.log(this.tableRow);
});
我还记录列表的值当应用程序加载时,当我点击它,它确实发生了改变。
然后我有一个函数来测试值是否已经改变了只是一个简单的警报功能。
greet: function() {
// `this` inside methods points to the Vue instance
alert('Hello ' + this.tableRow[0].name)
},
但该值不更新在函数中没有人知道为什么。
Vue的实例代码
export default {
data() {
return {
tableRow: [
{
"name": "1",
"numSongs": "2",
"Year": "3"
}
]
}
},
mounted: function() {
console.log(this.tableRow);
this.$nextTick(() => {
$("#table1 tr").click(function() {
var list = [];
var $row = $(this).closest("tr"),
$tds = $row.find("td");
list.push({ name: $tds.eq(0).text(), numSongs: $tds.eq(1).text(), Year: $tds.eq(2).text() });
this.tableRow = list;
console.log(this.tableRow);
});
});
},
methods: {
greet: function() {
// `this` inside methods points to the Vue instance
alert('Hello ' + this.tableRow[0].name)
},
}
}
你能告诉我它加入到这个问题刚才VUE实例代码 –
。 – DanielM96