petritr
1 year ago
28
1
Vue

loop json in vue 2 component

Posted 1 year ago by petritr

I have imported an Vue component and my goal is to use this component:

https://github.com/moreta/vue-search-select

I have problem passing the json data to the component.

data() {
    return {
        options: [
        ],
        searchText: '',
        item: {
            name: '',
            id: ''
        }
    }
},

I read the data with axios

axios.get('/api/users').then(({ data }) => {
    console.log(data)
    this.options = data;

})

the console log with return the data like:

0:{…}
1:{…}
2:{…}

Inside the first json

0:
id:(...)
information:(...)
address:(...)
zip:(...)

I need to pass the data like its in the example:

options: [
          { value: '1', text: 'aa' + ' - ' + '1' },
          { value: '2', text: 'ab' + ' - ' + '2' },
          { value: '3', text: 'bc' + ' - ' + '3' },
          { value: '4', text: 'cd' + ' - ' + '4' },
          { value: '5', text: 'de' + ' - ' + '5' }
],

How can pass the axios data like this ?

Please sign in or create an account to participate in this conversation.