[Chartjs]-Vue.js this.$el.getContext('2d') is not a function

6👍

this.$el in this case is a reference to div#container. What you want to do is use a ref.

ref is used to register a reference to an element or a child
component. The reference will be registered under the parent
component’s $refs object

<div class="container">
  <canvas ref="canvas" width="900" height="400"></canvas>
</div>

And then

this.$refs.canvas.getContext('2d') 

Leave a comment