[Vuejs]-Make Vuex state only accessible via getter

0👍

Options

  1. While not solving the problem, we could use "_" as a prefix to indicate variables that should not be accessed. This is a common convention and should be readable for an experienced programmer.
  2. Not exporting variables created in the store makes them accessible in the store, but not outside, mimicking the effect of a private variable on a class. (thanks to Lawrence Cherone)
  3. According to this MDN page:

Class fields are public by default, but private class members can be created by using a hash # prefix. The privacy encapsulation of these class features is enforced by JavaScript itself.

  1. We could use typescript to get access to the private identifier (typescriptlang.org).

Leave a comment