I'm using Vuejs inline template components where we register the component in a javascript file and the template in html.
the component looks something like this:
Vue.component('compare-benefits', {
data() {
// the "this" keyword in methods should refer to this object
return {
...state,
isLoading: false,
}
},
methods: {
getData() {
// I want the "this" keyword here to reference the object return in data above
this.isLoading = true;
}
}
})
If you are not familiar with Vue, whats happening here is that Vue framework will bind the this
keyword in your methods to the object you return from the data() method.
How do I use jsDoc here and tell it that the this
keyword here is in fact referencing that object?
EDIT: Primary reason for using jsDoc is not to create documentation but rather to have intellisense and type checking in vscode using @ts-check
Create JSDoc commentsPosition the caret before the declaration of the method/function or field to document, type the opening block comment /** , and press Enter . WebStorm generates a JSDoc comment with a list of parameters ( @param ) and return values ( @returns ), where applicable.
You can use most JSDoc type syntax and any TypeScript syntax, from the most basic like string to the most advanced, like conditional types.
JSDoc 3 is an API documentation generator for JavaScript, similar to Javadoc or phpDocumentor. You add documentation comments directly to your source code, right alongside the code itself. The JSDoc tool will scan your source code and generate an HTML documentation website for you.
VuePress is composed of two parts: a minimalistic static site generator with a Vue-powered theming system and Plugin API, and a default theme optimized for writing technical documentation. It was created to support the documentation needs of Vue's own sub projects.
The this
keyword in Vue framework
is an object of type Vue
. You can identify it by debugging your code within your getData
method or any other method. Moreover, the Vue data
are properties to this
. I have uploaded a screenshot below for you to see it from an example of my own that I am currently working on:
As a result, your code after jsDoc usage will be like this:
Vue.component('compare-benefits', {
data() {
return {
...state,
isLoading: false,
}
},
methods: {
/** @this Vue */
getData() {
this.isLoading = true;
}
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With