[Vuejs]-Vuejs and laravel -NaN value?

1👍

In your created function, you tell vue to run the functioin this.avancement with a parameter of this.projet.id. Since you setup your data object to be the following:

data() {
  return {
    progress:'',
    projets:{},
    projet:{
      id:''
    },
  }
}

This means that when your code executes the code inside the created hook, it will use the current state of your data.

created(){
  this.avancement(this.projet.id); // this.projet.id's value at this point is '' (empty string)
}

So when your function then runs the http request, you are sending this:

axios.get('/api/progress/'+'').then(({data})=>(this.progress =data.data));

This probably breaks your API because it requires an id of some sorts.

At this point, I dont have enough info from your application or goal to know why you run this at created. But a solution to fix this as it is right now would be to add a condition inside your avancement function to not run it if the id is not valid.

methods:{
  avancemant($id){
   if(isNaN($id)) {
      return
   }
    axios.get('/api/progress/'+$id).then(({data})=>(this.progress =data.data));;
  },
} 

Leave a comment