Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the dollar prefix ($) mean in Vue.js?

What is the meaning of the dollar character/symbol prefix before property names in Vue.js?

For example: this.$emit('clicked', 'demo')

like image 233
cluster1 Avatar asked Jul 04 '19 06:07

cluster1


People also ask

What does dollar sign mean in Vue?

$ is for public instance properties: As for the $ prefix, its purpose within the Vue ecosystem is special instance properties that are exposed to the user... Both are used to avoid collisions with property names chosen by component creators, such as props and data properties.

What does the dollar sign mean in JS?

Updated on July 03, 2019. The dollar sign ($) and the underscore (_) characters are JavaScript identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.

What is at symbol in VUE JS?

In your case, the @ symbol, symbol is shorthand for v-on . It can also be used when importing to resolve things.

What is the meaning of in Vue?

In Vue, $ means that you're using a Vue instance property or an Vue instance method. You can learn more about it on the documentation. Follow this answer to receive notifications.


1 Answers

The use of the $ and _ prefixes in Vue are explained here:

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

Specifically in the Detailed Explanation section.

_ is for private instance properties:

Vue uses the _ prefix to define its own private properties...

$ is for public instance properties:

As for the $ prefix, its purpose within the Vue ecosystem is special instance properties that are exposed to the user...

Both are used to avoid collisions with property names chosen by component creators, such as props and data properties.


The $ prefix is not only used by Vue's core APIs. It's also commonly used by libraries that add properties to components. e.g.:

  • Vuex adds $store.
  • Vue Router adds $route and $router.

These are both officially supported libraries but the same is true of many third-party libraries.

It can also be used by application code that creates global properties. A common example is adding $http to Vue.prototype (or globalProperties in Vue 3).

In all of these cases, the $ acts as an indicator to future developers that a property is defined elsewhere and not within the current component.

like image 193
skirtle Avatar answered Oct 09 '22 05:10

skirtle