I created a new component that will render a chart using Chart.js. I would like to access this component via a reference.
<kpis-linechart name="inv-speed" ref="inv-speed-chart" :information="team.invoice_details">
A chart with chart.js is created using <canvas id="chart-id"></canvas> in the html.
I would like assign the chart id the same value as the ref value.
Is there a way to get the ref. name from the component ?
Example : this.$ref_name
This is my code so far :
Vue.component('kpis-linechart',{
template : '#kpis-linechart-template',
props : {
information : Object,
name : String
},
// I WANT TO REPLACE THIS CODE IN ORDER TO GET THE REF NAME AS ID //
// I WANT TO REPLACE THIS CODE IN ORDER TO GET THE REF NAME AS ID //
computed : {
id_chart(){
return this.name + '-chart'
}
},
methods : {
updateChart(){
this.chart = new Chart(document.getElementById(this.id_chart),{
type : 'line',
data : {
labels : ['hola','como','estas'],
datasets : [
{
label : 'Queso',
data : [1,2,4]
}
]
}
})
}
},
mounted(){
this.updateChart()
console.log('CREATING CHART')
// console.log(this.information)
console.log(this)
}
})