Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: type is undefined

I want to set my array from state to v-select, this is my storage:

export default ({
state: {
  trainerList: []
},
getters: {
  TRAINER_LIST(state){
    console.log(state.trainerList)
    return state.trainerList
  }
},
mutations: {
  SET_TRAINER_LIST_TO_STATE(state, trainerList){
    return state.trainerList = trainerList
  }
},
actions: {
    async GET_BRANCH_FROM_API({commit}){
        return axios.get(`${BASE_URL}/api/trainer-list/`,
        {
        headers:{
            Authorization: 'Token ' + sessionStorage.getItem('usertoken')
        }
        })
        .then((response)=>{
            commit('SET_TRAINER_LIST_TO_STATE', response.data)
        })
    },
},
modules: {
}

})

this is my getter and action in component:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

computed:{
    ...mapGetters([
        'TRAINER_LIST'
    ])
},
created(){
    this.GET_BRANCH_FROM_API()
}

my select from template:

                             <v-select
                                label="Выберите тренера"
                                :items="TRAINER_LIST"
                                variant="solo"
                                class="mt-3"
                                :item-text="TRAINER_LIST.coach_name"
                                item-value="id"
                                clearable
                                v-model="form.trainerId"
                            ></v-select>

when I click on select, empty elements appear there, when an element is selected, an object, an object is highlighted

enter image description here

enter image description here

and displaying this error:

enter image description here

my state is returning data correctly, as I understand it, the select cannot determine the type of my state?

enter image description here

Can anybody help me, please? I have no idea what to do, because I need array here

>Solution :

Referring to the docs, Change your v-select to:

 <v-select
 label="Выберите тренера"
 :items="TRAINER_LIST"
 variant="solo"
 class="mt-3"
 item-text="coach_name"
 item-value="id"
 clearable
 v-model="form.trainerId"
 ></v-select>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading