20 lines
504 B
TypeScript
20 lines
504 B
TypeScript
import { watchEffect, toValue, type MaybeRefOrGetter } from 'vue';
|
|
import useDJSSRContext from "@/useDJSSRContext.ts";
|
|
|
|
export default function useHead(params: {
|
|
title: MaybeRefOrGetter<string>,
|
|
}) {
|
|
const context = useDJSSRContext();
|
|
|
|
if (context) {
|
|
context.head.title = params.title;
|
|
} else {
|
|
watchEffect(() => {
|
|
const newTitle = toValue(params.title);
|
|
if (newTitle) {
|
|
document.title = newTitle;
|
|
}
|
|
});
|
|
}
|
|
}
|