head icon indicating copy to clipboard operation
head copied to clipboard

`vueuse/head` doesn't support events when creating an element

Open ms-fadaei opened this issue 3 years ago • 3 comments

Hi everybody. I recently worked on new features that bring script loading strategy to the Nuxt. The problem is when I add some events to the script component (provided by nuxt as sugar syntax of useMeta), it turned into attributes and prints the event function string on the element.

<script src="./mock.js?t=49" strategy="immediate" onload="function() { console.log('loaded')"></script>

ms-fadaei avatar Dec 11 '21 07:12 ms-fadaei

hmm I think that should be implemented as a standalone <Script /> component outside vueuse/head.

egoist avatar Dec 11 '21 09:12 egoist

Nuxt already did this. But the point is there is a problem when using events. As Vue 3 described, events attached to the component and not present in emits list, must be attached to the root element of the component. I think the script element created via vueuse/head should support events.

ms-fadaei avatar Dec 11 '21 09:12 ms-fadaei

I got your point 👌

egoist avatar Dec 11 '21 10:12 egoist

This is available with the useHeadRaw function.

Let me know if you have any questions

harlan-zw avatar Oct 05 '22 00:10 harlan-zw