Skip to content
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

Highcharts this.$refs undefined in mounted #55

Closed
poloma opened this issue Apr 24, 2018 · 4 comments
Closed

Highcharts this.$refs undefined in mounted #55

poloma opened this issue Apr 24, 2018 · 4 comments
Labels

Comments

@poloma
Copy link

poloma commented Apr 24, 2018

I'm trying to add data once the component is mounted by accessing this.$refs.highcharts but Vue says it's undefined

methods: {
  updateChartData () {
    const { chart } = this.$refs.highcharts
    chart.series[0].setData(this.chartData, true)
  }
},
mounted () {
  this.updateChartData()
}

Error in mounted hook: "TypeError: Cannot read property 'chart' of undefined"'

Any ideas? Or better way of initializing data with a calculated field.

@weizhenye
Copy link
Owner

Do you forgot to write the ref props?

<highcharts :options="options" ref="highcharts"></highcharts>

@poloma
Copy link
Author

poloma commented Apr 25, 2018

No, I am able to update the ref on a click but it seems the ref is just not available during the mounted hook.

@weizhenye
Copy link
Owner

Is your <highcharts> controlled by v-if which is shown at next tick? Child component should be mounted before parent component. Could you provide a minimal example to reproduce it?

@poloma
Copy link
Author

poloma commented May 1, 2018

@weizhenye Thank you that was it! My mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants