0

Considering vue.js version 3: Is there any chance to use this-reference inside an anonymous data function (see this.initialColor in the following code example)?

export default {
  name: 'MyColorPicker',
  props: ['initialColor'],
  data: () => ({
      localCopy: this.initialColor,
    }),

This code returns the error that this is undefined:

(Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'initialColor')).

If I change data definition to the following, the code works:

  data() {
    return {
      localCopy: this.initialColor
    }
  }

Thanks for your input!

Freude
  • 819
  • 1
  • 10
  • 18

0 Answers0