Should .vue file need access modifiers? like public/protected/private in Java #14283
xuyimingwork
started this conversation in
Ideas
Replies: 1 comment
-
Draft Specification: Vue File-Level Access Control1. The Modifier Matrix
2. Project Example & EnforcementImagine a User Management feature which has a A. The PrivateUserListItem.vue is a small part of the UserList.vue <script setup>
/** @access private(UserList.vue) **/
</script>
B. The Strict Protected (Same Folder)UserTheme.vue defines the look for the whole feature. <script setup>
/** @access protected(User) strict **/
</script>
C. The ProtectedUserIcon.vue is used by all components under the User/ folder. <script setup>
/** @access protected(User) **/
</script>
. The Publica component can import by any component in project. <script setup>
/** @access public **/
</script>or no comment(default behavior).
3. ESLint Implementation LogicTo enforce this, a custom ESLint rule would perform these three checks whenever an import is detected:
4. Why this works for the Vue Ecosystem
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
vuejs/rfcs#96
vuejs/rfcs#517
VueUse now has createReusableTemplate function to create sub component in a file.
But I think break large component into sub component is a real requirement, the key problem is:
So, my idea is: this is a problem of js missing access modifiers, unlike Java, we don't have public protected private access modifiers.
A component in Vue is like a class in Java, a .vue file in Vue is like a .java file in Java.
Why not just introduce the best practice of access modifiers in Java, which examined by millions of developer, to solve the problem we facing? Just using tools like eslint, add a new rule and config .vue's access modifiers by comment, maybe enough.
Beta Was this translation helpful? Give feedback.
All reactions