Should .vue file need access modifiers? like public/protected/private in Java #14283
Replies: 2 comments
-
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.
-
|
Hey @xuyimingwork, Working with Vue reactivity system and compilers can sometimes present interesting edge cases. A few quick things to consider regarding this topic:
I highly recommend checking out the Vue DevTools extension to inspect the component tree and verify if the state is updating as expected. Let me know if you want to dig deeper into the specific component logic. Hope this points you in the right direction! Let me know how it goes. Happy coding! |
Beta Was this translation helpful? Give feedback.
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