我使用日期選擇器並使用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