-
-
Notifications
You must be signed in to change notification settings - Fork 838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A Gotcha on component creation. #92
Comments
Well, it makes sense if you think about it. You are creating a component: // CommitChart.js
import { Bar } from 'vue-chartjs'
export default Bar.extend({
mounted () {
// Overwriting base render method with actual data.
this.renderChart(data, options)
}
}) But, you are extending the base chart component. Which is for example this one: https://github.com/apertureless/vue-chartjs/blob/develop/src/BaseCharts/Bar.js Now in your commitchart.js or in your case your commitchart.vue you have access to all data models and all props and all methods, which are defined in the base chart. You can access the And you can create new props and data models in your commit chart component and add custom logic to it. However, if you create a And if you have an empty template tag in your component it will replace the whole canvas and template defined in the base chart, with... nothing ... and you lose the :) |
Well, that 'thinking' part always gets me! I'm new to JavaScript, and am still learning. It does make sense once one understand what you so clearly explained. Thanks so much. |
You're welcome :) |
Lovely explanation, just got saved from this too |
Thanks for your nice explanation :) |
Well its not really a disadvantage. In the very rare cases where you do need to change the template of the div + canvas, you still can. You just need to make sure that the And merging templates generally does not make much sense if you think about it. In which cases would you want to merge the template part of two components ? |
I am just integrating this into a project. I've created a component copy-pasted from 'How to use' section, the Bar chart. When I then used that component, it blew up with an error:
Cannot read property 'getContext' of undefined
This puzzled me. :) The issue is that in my Vue component, I had an (empty) template tag, as I just automatically do that to every new .vue file. Removing the template tag resoled the issue.
I did not see any reference to forbidding the empty template tag. I thought perhaps it'd be worth mentioning.
Thanks.
The text was updated successfully, but these errors were encountered: