Reputation:
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)
Upvotes: 0
Views: 83
Reputation: 1688
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.
Upvotes: 1