我使用日期选择器并使用javascript将日期传递给vue实例,但在第一次使用v-for呈现列表后,当我调用功能与其他日期,它保持前一个数据显示。 这里是我的功能有:当Ajax更新数据时,无法更新v-for列表
function updateDate(fdate) {
var datefieldVal = document.getElementById('date').value;
var locationfieldVal = document.getElementById('location').value;
if (datefieldVal && locationfieldVal) {
var tslot = new Vue({
el: '#time-slots-container',
data: {
slot: {}
},
mounted: function() {
this.fetchTimeslot();
},
methods: {
fetchTimeslot: function() {
var that = this;
$.ajax({
type: "GET",
url: timeslotApiURL + "?date='" +fdate+ "'",
contentType: "application/json;",
dataType: "json",
success: function (data) {
that.slot = JSON.parse(data.d);
setTimeout(showTimeSlotAndButton, 500);
}
});
}
});
}
}
人有想法,如何更新使用新的时隙数据V型的名单?谢谢
嗨,GuyC,谢谢你的回复。是的,我检查了收到的数据是正确的,使用上面的语法后,也似乎不工作,它保留了前一个数据。我认为槽数据已经改变,只是呈现列表没有反应,任何想法? – Winston
抱歉,刚刚注意到您每次运行updateDate时都试图重建vue实例。更新回答 – GuyC
将Vue代码移到updateDate函数之外后,如何调用并将update日期参数传递给updateDate函数中的vue? – Winston