Created
March 22, 2025 09:58
-
-
Save atomjoy/ad6192d983bfd55035d7eb6450330858 to your computer and use it in GitHub Desktop.
Change page title in Vue 3.
This file contains hidden or 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
<template></template> | |
<script setup> | |
import { useI18n } from 'vue-i18n'; | |
import { watch, onMounted } from 'vue'; | |
const { t, locale } = useI18n({ useScope: 'global' }); | |
const props = defineProps({ | |
title: { | |
type: String, | |
default: '', | |
}, | |
}); | |
onMounted(() => { | |
document.title = t(props.title); | |
}); | |
watch( | |
() => locale.value, | |
(lang) => { | |
document.title = t(props.title); | |
} | |
); | |
watch( | |
() => props.title, | |
(lang) => { | |
document.title = t(props.title); | |
} | |
); | |
</script> | |
<!-- | |
// Require in main.js createI18n(options) | |
allowComposition: true, | |
globalInjection: true, | |
legacy: false, | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment