search

Home  >  Q&A  >  body text

In Vue.js, the meaning of the dollar sign ($) prefix refers to the internal properties or methods of the Vue instance. These properties and methods are used internally by the Vue.js framework, and it is generally not recommended to access or modify them directly. The dollar sign prefix is ​​to distinguish the internal properties and methods of the Vue instance from the user-defined properties and methods.

<p>In Vue.js, what is the meaning of the dollar sign prefix in front of the property name? </p> <p>For example: <code>this.$emit('clicked', 'demo')</code></p>
P粉199248808P粉199248808474 days ago841

reply all(1)I'll reply

  • P粉833546953

    P粉8335469532023-08-15 11:14:15

    In Vue, an explanation of using the $ and _ prefixes can be found here:

    https://v2.vuejs.org/v2/style-guide/#Private-property-names-essential

    Details are explained in the section.

    _For private instance properties:

    $ is used for public instance properties:

    Both are used to avoid conflicts with property names chosen by the component creator, such as props and data properties.

    The

    $ prefix is ​​not only used by Vue’s core API. It is also commonly used in libraries that add properties to components. For example:

      Vuex adds
    • $store.
    • Vue Router adds
    • $route and $router.
    These are officially supported libraries, but so are many third-party libraries.

    It can also be used by application code to create global properties. A common example is adding

    $http to Vue.prototype (or globalProperties in Vue 3).

    In all these cases,

    $ serves as an indicator to future developers that the property is defined elsewhere, not inside the current component.

    reply
    0
  • Cancelreply