1

I have just started Vue.js and now I have a problem with using the functions inside the life cycle methods.

<script>
export default {
  name: 'MapComponent',
  data () {
    return {
      restaurants: [],
      menus: []
    }
  },
  mounted: () => {
    this.augmented(2)
  },
  methods: {
    augmented: function (variable) {
      return (2 * variable)
    }
  }
}
</script>

My code looks like above. The problem is that when I call function augmented I get an error which is "Error in mounted hook: "TypeError: _this.augmented is not a function"

Could someone explain that why function augmented is not found?

Thank you for your help.

Jamel
  • 33
  • 1
  • 4

1 Answers1

3

Don't use arrow functions here, because arrow functions assign a different context to "this" keyword in Vue.

mounted: function() { this.augmented(2) };
knizhnikov
  • 299
  • 1
  • 7