Skip to content

Instantly share code, notes, and snippets.

@mvsde
Last active February 22, 2023 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvsde/a7749f565e4195627e86f5a53bff010e to your computer and use it in GitHub Desktop.
Save mvsde/a7749f565e4195627e86f5a53bff010e to your computer and use it in GitHub Desktop.
Split Vue 3 attrs into root and bind attrs for transparent components
import { computed, useAttrs } from "vue";
export function useBindAttrs() {
const attrs = useAttrs();
const rootAttrs = computed(() => ({
class: attrs.class,
style: attrs.style,
}));
const bindAttrs = computed(() => {
const { style, class: cls, ...rest } = attrs;
return rest;
});
return { rootAttrs, bindAttrs };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment