I want to be able to make an ajax call and to use the results returned to generate the options of a drop-down using vue.js. I can do this:
<select v-model="selected">
<option v-for="option in options" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
<span>Selected: {{ selected }}</span>
.js文件
new Vue({
el: '...',
data: {
selected: 'A',
options: [
{ text: 'One', value: 'A' },
{ text: 'Two', value: 'B' },
{ text: 'Three', value: 'C' }
]
}
})
但我不想让我的选项硬编码,而是来自ajax调用.
Ajax调用如下所示:
function pullEmployees(){
var eventOwnerId = $('#eventOwner').val();
var eventOwnerName = $('#eventOwner :selected').text();
$.ajax({
url: "employees.cfm",
data: {
eventOwnerId: eventOwnerId,
eventOwnerName: eventOwnerName,
method : "updateOwners"
},
success: function(results) {
// results will have a list of objects where each objects has two properties (ID and Value)
}
});
}
I am really new in vue.js and I would appreciate if someone can help.