Chartjs-Vuejs parameters in props

4👍

It depends on what you are trying to do. If you want to pass an actual function and not the result of a function, you can do:

<line-chart class="card-content" :chartData="() => lineData2('Temp')" :options="options" :width="800"></line-chart>

 

Which will pass the lineData2 function itself, however, it will still be executed in the parent scope and not in the component scope, so it won’t have any access to the components this context.

Here’s a JSFiddle: https://jsfiddle.net/rz8c1v4L/

If you just want to pass the result of the function then what you are doing is fine.

0👍

Yes you can. As long as your function returns a value. Everything should work.

0👍

Yes you can! You can achieve that by mentioning the type of your prop, as it is clearly written in Vue’s documentation. For e.g.

Vue.component('example', {
  props: {
    propA: {
      type: function
    }
  }
})

Also checkout this link

Leave a comment