0

i have send my data wit axios on array (mySplitDays[splitDayIndex]=splitDay) but i have a error...

components: { VueCal },
data() {
    return {
        users:[],
        mois:[],
        assignments:[],
        selectedEvent: {},
        showDialog: false,
        events: [],//recuperer tache ici
        minCellWidth: 400,
        minSplitWidth: 150,
        splitDays:mySplitDays        
    };
},
async mounted() {
    let response = await axios
    .get(`${process.env.***}/users?role=***&active=***`)
    let mySplitDays = response.data
    for (let splitDayIndex in mySplitDays){
        let splitDay= mySplitDays[splitDayIndex]
        splitDay.class = splitDay.lastname
        splitDay.label = splitDay.lastname
        mySplitDays[splitDayIndex]=splitDay
    }
}

[Vue warn]: Error in data(): "ReferenceError: mySplitDays is not defined"

ReferenceError: mySplitDays is not defined

[Vue warn]: Error in render: "TypeError: Cannot read property 'length' of undefined"

TypeError: Cannot read property 'length' of undefined at Proxy.render (eval at ./node_modules/vue-loader/lib/template-compiler/index.js?{"id":"data-v-aae30ed8","hasScoped":true,"transformToRequire":{"video":["src","poster"],"source":"src","img":"src","image":"xlink:href"},"buble":{"transforms":{}}}!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./src/components/Dashboard.vue (app.js:2705), :15:31)

3
  • what is the content of reponse? It looks like response.data might be null. Try calling the API from postman to see if it works Commented Oct 9, 2019 at 9:27
  • which answer ? when i'm still in axios i have all of my data Commented Oct 9, 2019 at 9:31
  • try running console.log(response.data) after the axios call Commented Oct 9, 2019 at 9:45

1 Answer 1

1

You are trying to assign mySplitDays to data when the component is created. There is no variable called that existing at that point. You should add a default value such as an empty array to splitDays. Empty array is probably the best default value as it has a length property and thus if you use that somewhere in the template it will not cause issues. Then inside the mounted function assign the result from axios to data.

Sign up to request clarification or add additional context in comments.

2 Comments

ok but after "splitDays:[]" where should i put mySplitDays = splitDays?
You can assign a value to splitDays inside mounted using this.splitDays = mySplitdays