1

I have a VueJS component, now I'm getting from JSON response which I want to export into a html select box.

My VueJS method:

getTaskList() {
    axios.get('/api/v1/tasklist').then(response => {
        this.taskList = this.data.taskList;
    });
}

I found example in VueJS documentation but there is still the problem with method...

How can I export this response into a selectbox, I know how to work with v-for, but I don't know exactly how to initialize this data in HTML (with v-bind, or something like that)?

1
  • What are you getting exactly from /api/v1/tasklist? Commented Dec 8, 2017 at 10:04

1 Answer 1

1

I don't know what's in the taskList items but you can simply bind those data in option tags :

<select v-model="selectedTask">
  <option v-for="task in taskList" :key="task.id" :value="task.value">{{ task.label }}</option>
</select>
Sign up to request clarification or add additional context in comments.

3 Comments

I know this, but where I have to define v-model="selectedTask" in JS code?
Solved, I called this function in mounted area and not works everything (this. getTaskList())
You could even call this method in the created hook, so your data will be ready as soon as possible (you don't need to wait for the element to be mounted to load those data). Sorry I didn't understand your question in the first place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.