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.
- [Vuejs]-Vue-jest Failed to collect coverage from vue file
- [Vuejs]-Evaluating an array within array in VueJS
- [Vuejs]-How to implement dialog content destroy function after close vuetify dialog?
- [Vuejs]-Clearing input field when using Vue with Vuex
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
Source:stackexchange.com