Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  13] [ 6]  / answers: 1 / hits: 28122  / 5 Years ago, thu, july 4, 2019, 12:00:00

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



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


More From » vue.js

 Answers
4

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


https://v2.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.


[#51926] Thursday, June 27, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alvin

Total Points: 55
Total Questions: 101
Total Answers: 109

Location: Sudan
Member since Tue, Aug 3, 2021
3 Years ago
;