Skip to content
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

Shorthand attributes/props #5330

Closed
roonie007 opened this issue Jan 26, 2022 · 1 comment
Closed

Shorthand attributes/props #5330

roonie007 opened this issue Jan 26, 2022 · 1 comment

Comments

@roonie007
Copy link

What problem does this feature solve?

Having an attribute where the name and value are the same is common case in many of the projects I have worked on.
You find yourself rewriting the same word twice in many components.

Example

my-component.vue

<template>
  <a :id="id" :href="href"> {{title}} </a>
</template>

<script lang="ts" setup>
defineProps({
  id: String;
  title: String;
  href: String;
});
</script>

App.vue

<template>
  <my-component :id="id" :title="title" :href="href" />
</template>

<script lang="ts" setup>
  const id = 'my-id';
  const title= 'my-title';
  const href = 'http://my-link.com';
</script>

What does the proposed API look like?

As you can see in the following example, it's cleaner and easier to read when attribute names aren't repeated twice.

my-component.vue

<template>
  <a :id :href> {{title}} </a>
</template>

<script lang="ts" setup>
defineProps({
  id: String;
  title: String;
  href: String;
});
</script>

App.vue

<template>
  <my-component :id :title :href />
</template>

<script lang="ts" setup>
  const id = 'my-id';
  const title= 'my-title';
  const href = 'http://my-link.com';
</script>
@roonie007
Copy link
Author

roonie007 commented Jan 26, 2022

Duplicated vuejs/vue#2877 and looks like @yyx990803 is not a big fan of it vuejs/vue#2877 (comment).

But having personally tried it with Svelte, it's a very useful feature https://svelte.dev/tutorial/dynamic-attributes

@github-actions github-actions bot locked and limited conversation to collaborators Oct 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant