-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use <script setup name="cpnName"> instead of two <script> #5218
Comments
This might be a good feature. |
I'm trying to switch Element Plus to IMHO, Maybe Vue can provide a marco API called Example: <script setup lang="ts">
defineOptions({
name: 'Foo',
inheritAttrs: false,
})
defineProps<Props>()
// ...
</script> and it transforms to <script lang="ts">
export default {
name: 'Foo',
inheritAttrs: false,
}
</script>
<script lang="ts" setup>
defineProps<Props>()
// ...
</script> Related issue: element-plus/element-plus#5709 (comment) UPDATE: |
I think I like this proposal better than defineOptions, if <script> behaves like a vue component that accepts props like options that would be amazing, then we could pass options like
|
They wrongly closed #5633 as a duplicate of this, so I'm putting this here so it doesn't just disappear and because it's related enough to be in here anyway. I saw some people on Twitter that noted Vue's general usage of default exports for all components. Some people, and myself to an extent, think that named exports are a better practice, but I love So I was thinking about enhancing E.g. <script setup namedExport="MyComponent">
// ...
</script> Would compile to export const MyComponent = {
// ...
} If we want to simplify and combine these attributes into a cohesive bunch we can use E.g. <script setup name="MyComponent" namedExport>
// ...
</script> Would compile to export const MyComponent = {
name: "MyComponent",
// ...
} So if you don't want to set a component name, or if you want the exported name and the component name to be different, set <script setup name="ParentGroup.ChildComponent" namedExport="ChildComponent">
// ...
</script> Would compile to export const ChildComponent = {
name: "ParentGroup.ChildComponent",
// ...
} |
When does the official plan to add this function? |
When does the official plan to add this function? |
I made a plugin unplugin-vue-define-options to implement this feature, if you really need it. |
NOW! I have the new ideas, if I want to write the JSX in E.g. <script lang="ts">
setup() {
return () => (
<div></div>
)
}
</script> —————— <script setup>
const msg = ref('hi')
defineTemplate(() => (
<div>{{ msg }}</div>
))
</script> use this API, the file just need one label |
@gumingWu I think we can discuss this API in a new issue. |
I think try not to change |
At the very least, it fits with |
I think a script tag with name= "XXX" is the best implementation |
I support <script name=" xxx" > |
1693924 automatically infers component name based on filename. |
When a component contains multiple subcomponents, the directory structure looks like this: If it's |
I don't think this should have been closed, because we're all aware that it automatically infers component names. We want to be able to explicitly write them because file name isn't always the most useful. Anyway, @Mrlilili a way you can handle your situation is to have OtherHome.vue plus an index.js (or .ts obviously) with this: import OtherHome from './OtherHome'
export default OtherHome And while that might be annoying to do, it'll help with your problem and it's simple enough to create a tiny code generator to handle most of this. You also have the separate |
Or we need a way to customize (webpack option) how this name is generated with a function that takes the path in param and outputs the name |
What problem does this feature solve?
When I create a component vue file,I will write two script in it,first script maintain the component name,sceond script use script setup syntax,I think it need to be optimized
<script> export default { name: 'ChildCpn' } </script>E.g
before
after
<script setup name="ChildCpn"></script>so cool~
What does the proposed API look like?
<script setup name="ChildCpn">The text was updated successfully, but these errors were encountered: