I have a Vue.js v2.6 project with TypeScript v.4.3 "under the hood".
My problem: I cannot find any documentation that clears up, if it makes sense to use access modifiers
in Vue components and how to use them correctly.
I searched through articles, Vue.js docs, and StackOverflow, without any findings. (The Vue.js docs ignore their existence completely!)
This is how I am currently using access modifiers in my Vue components:
Template part of myComponent.vue:
<template>
<div>
<!-- accessing some of the fields of the class here e.g. the getter -->
</div>
</template>
Script part of myComponent.vue:
<script lang="ts">
import { Vue, Component, Prop, Emit } from "vue-property-decorator";
@Component()
export default class MyComponent extends Vue {
@Prop() public readonly myPropertyVariable!: boolean;
public myVariable!: string; // accessed in template
private myInternalVariable!: boolean; // not accessed in template
public get myGetterVariable(): string {
// obviously accessed in template (getter)
}
@Emit()
public change(): void {}
@Action
public doAction(): void {}
public mounted(): void {}
public myMethod(): boolean {
// accessed in template
}
private myInternalMethod(): boolean {
// not accessed in template
}
}
</script>
I hope, this is not an opinion-based question. I am assuming there a facts that confirm the meaningfulness of access modifiers in Vue components. I have a strong, possibly irrational resistance to omit them all.
Btw: I am coding in Rider, the access modifiers might be useful for IDE code analysis.