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粉199248808
2023-08-14 11:37:15
<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>
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:
$
Both are used to avoid conflicts with property names chosen by the component creator, such as props and data properties.is used for public instance properties:
$
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
These are officially supported libraries, but so are many third-party libraries..
and
$router.
$http
In all these cases,to
Vue.prototype(or
globalPropertiesin Vue 3).
$
serves as an indicator to future developers that the property is defined elsewhere, not inside the current component.