Skip to content

Instantly share code, notes, and snippets.

@atomjoy
Created March 22, 2025 09:57
Show Gist options
  • Save atomjoy/8ed2b63754bbcfae1f2aecec02449610 to your computer and use it in GitHub Desktop.
Save atomjoy/8ed2b63754bbcfae1f2aecec02449610 to your computer and use it in GitHub Desktop.
Change page description in Vue 3.
<template></template>
<script setup>
import { watch, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
const { t, locale } = useI18n({ useScope: 'global' });
const props = defineProps({
description: {
type: String,
default: '',
},
});
const el = document.querySelector('head meta[name="description"]');
onMounted(() => {
el.setAttribute('content', t(props.description));
});
watch(
() => locale.value,
(lang) => {
el.setAttribute('content', t(props.description));
}
);
watch(
() => props.description,
(lang) => {
el.setAttribute('content', t(props.description));
}
);
</script>
<!--
// Required 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