我正在從 api 檢索數據列表,需要填充特定<select></select>標簽,這些標簽與幾個單選按鈕相關聯,其中一些數據為<options></options>. 單選按鈕等待事件 ( @change/ @click) 并執行和 axios get 請求。一切正常。我單擊單選按鈕并檢索數據作為響應(vue 工具也顯示正確的數據)但標簽<option></option>沒有更新?,F在,當我單擊另一個單選按鈕時,我再次從 api 獲取正確的數據,但現在標簽<option></option>正在使用先前響應的數據進行刷新。模板<!-- CREATING 7 RADIO BUTTONS FOR THE CURRENT WEEK FROM MON-SUN --><div class="wrapper" v-for="item in inputDetails"> <input :id="'datetime[0]['+item.labelText+']'" type="radio" name="datetime[0][date]" v-model="formData.datetime[0].date" :value="item.inputValue" @change="getTimes" /></div><!-- CREATING THE TIME PICKER --><select id="datetime[0][time]" name="datetime[0][time]" v-model="formData.datetime[0].time"> <option selected="selected"></option> <option v-for="item in selectOptionTimes[0]" :value="item.value">{{ item.label }}</option></select><!-- 2 MORE RADIO BUTTON SECTION AND TIME PICKER SECTIONS WITH DIFFERENT INDEXES<input id="datetime[1][time]"... -->腳本data() { return { formData: { datetime: [ {date: '', time: ''}, {date: '', time: ''}, {date: '', time: ''}, ] } selectOptionTimes: [], }},methods: { getTimes: function (current) { let instanceIndex = current.currentTarget.id.match(/(?<=\[)([0-9])(?=])/g)[0]; // getting the index of the current datetime section axios.get('/api-url', { params: { location_id: this.formData.location_id, date: current.currentTarget.value } }).then(response => { this.selectOptionTimes[instanceIndex] = response.data; }); }}有人知道這里的問題是什么嗎?
如何在 axios 請求后修復 vuejs 中的值更新延遲?
largeQ
2023-06-15 17:26:33