vueuse / head

Document head management for Vue. Powered by Unhead. - 🌇 Sunset

Home Page:https://unhead.unjs.io/setup/vue/installation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get type of script from useHead()?

nestle49 opened this issue · comments

How to get type of script from useHead()?

Hi @nestle49

Would you further explaining what you mean, maybe with a code example as well?

Before with vue-meta used MetaInfo['script'], now i used Script, but I'm force need 'as' syntax

// eslint-disable-next-line import/no-extraneous-dependencies
import { Script } from '@unhead/schema';

const scripts: Script[] = [];

scripts.push({
                innerHTML: [
                    `bodyScript`
                ]
                    .filter(notEmpty)
                    .join('\n')
            } as Script);
useHead({
    script: [...scripts],
    link: []
});

I need equivalent MetaInfo['script']

Try something like this

import type { ReactiveHead } from '@vueuse/head'

const script: ReactiveHead['script'] = [];

script.push({
  src: 'https://unpkg.com/@unhead/vue@latest/dist/vue.esm-browser.js',
  defer: true
})

useHead({
  script,
})

Thanks, but inside ReactiveHead['script'] doesn't exist 'callback' property

scripts.push({
    src: '',
    async: true,
    callback: () => {},
    json: {}
});

That's because callback isn't a valid field, neither is json. You should refer to the docs, specifically the DOM events if you need some behaviour similar to callback

https://unhead.harlanzw.com/guide/guides/dom-event-handling