Last active
February 22, 2023 12:30
-
-
Save mvsde/a7749f565e4195627e86f5a53bff010e to your computer and use it in GitHub Desktop.
Split Vue 3 attrs into root and bind attrs for transparent components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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