Subscribe on changes!

Vue 能否内置在 setup 语法糖设置 name ?Can Vue set name in the setup syntax?

avatar
Jul 27th 2022

What problem does this feature solve?

Chinese

一些第三方 vite 插件 unplugin-vue-setup-extend-plus 实现了功能,但一直会出现一些不可预期的错误。在使用 script setup 语法糖的时候,如果再新建一个 script 来设置组件的 name 不免有些冗余和麻烦,所以建议 vue 内置此功能

例:

<script lang="ts" setup name="MyComponent">
 // code...
</script>

English

Some third-party vite plug-ins, such as unplugin-vue-setup-extend-plus, have implemented functions, but there have been some unexpected errors. When using script setup syntax sugar, if you create a new script to set the name of the component, it will inevitably be redundant and troublesome, so it is recommended that this function be built into Vue

Example:

<script lang="ts" setup name="MyComponent">
 // code...
</script>

What does the proposed API look like?

<script lang="ts" setup name="MyComponent">
 // code...
</script>
avatar
Jul 27th 2022

script setup 的name命名是根据文件名来的

MyComponent.vue -> 组件 name : MyComponent

avatar
Jul 29th 2022

那样可以实现递归组件吗? @AlanSean

avatar
Jul 29th 2022
avatar
Jul 29th 2022

那样可以实现递归组件吗? @AlanSean

script steup 文档 -> 递归组件

建议认真的再复习一下单文件组件