PhpStorm 2020.3 Help

Code Inspection: Data function

This inspection warns if data property of Vue component is not a function.

When defining a component, data must be declared as a function that returns the initial data object, because there will be many instances created using the same definition. If we still use a plain object for data, that same object will be shared by reference across all instances created! By providing a data function, every time a new instance is created, we can simply call it to return a fresh copy of the initial data.

Suppress an inspection in the editor

  1. Position the caret at the highlighted line and press Alt+Enter or click the Intention action icon.

  2. Click the arrow next to the inspection you want to suppress and select the necessary suppress action.

Last modified: 08 March 2021