feat(i18n): 添加国际化支持,更新语言切换功能
All checks were successful
/ build-and-deploy-to-vercel (push) Successful in 2m20s
/ depcheck (push) Successful in 2m27s
/ playwright (push) Successful in 2m1s

This commit is contained in:
严浩
2024-11-06 17:44:32 +08:00
parent e2f60c32a3
commit 40752e555f
6 changed files with 94 additions and 17 deletions

View File

@ -15,15 +15,23 @@ definePage({
});
import type { FunctionalComponent } from 'vue';
import { useI18n } from 'vue-i18n';
const { locale } = useI18n();
const handleLanguageChange = (event: Event) => {
const select = event.target as HTMLSelectElement;
locale.value = select.value;
};
// https://cn.vuejs.org/guide/extras/render-function#typing-functional-components
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const FComponent: FunctionalComponent<{ prop: string }> = (props, context) => (
<>
<div border="1 solid pink" text="pink">
<span>This is a functional component with prop: {JSON.stringify(props)}</span>
</div>
</>
// <>
<div border="1 solid pink" text="pink">
<span>This is a functional component with prop: {JSON.stringify(props)}</span>
</div>
// </>
);
</script>
@ -36,7 +44,16 @@ const FComponent: FunctionalComponent<{ prop: string }> = (props, context) => (
<li><router-link :to="{ name: '中文页面' }">中文-页面.page.vue</router-link></li>
<li><router-link :to="{ name: 'Api' }">Api</router-link></li>
</ul>
<FComponent prop="Hello World" />
<div b="1px solid pink" mt-8>
<select :value="locale" @change="handleLanguageChange">
<option value="zh_CN">中文</option>
<option value="en_US">English</option>
</select>
<h1>{{ $t('message.hello') }}</h1>
</div>
<FComponent prop="Hello World" style="margin-top: 8px"></FComponent>
<div text-orange></div>
<div b="1px solid pink" mt-8>