Bandolero
Bandolero

Reputation: 55

Vue.js - Trying to pass object from data() to a mounted() function

I am trying to pass the grid array to the createGridChart, however, this is giving me an error:

“grid is not defined”.

export default {
    data() {
      return {
        grid: [],
      }
    },
    mounted() {
      this.createGrid();
      this.createGridChart('grid-chart', 'pie', grid);
(...)

What would be the correct way to the the grid inside the function so that I can manipulate it to my liking?

Upvotes: 2

Views: 2444

Answers (1)

Sajib Khan
Sajib Khan

Reputation: 24156

You need to change grid to this.grid.

export default {
  data() {
    return {
      grid: [],
    }
  },
  mounted() {
    this.createGrid();
    this.createGridChart('grid-chart', 'pie', this.grid);
  (...)

Upvotes: 3

Related Questions