feat(i18n): 引入i18n,标题不生效,另外还有报错提示出现

This commit is contained in:
菲鸽
2024-01-29 14:48:07 +08:00
parent 61f3b4f1ee
commit 33061591a4
9 changed files with 54 additions and 19 deletions

3
src/locale/en.json Normal file
View File

@@ -0,0 +1,3 @@
{
"app.name": "En Title"
}

17
src/locale/index.ts Normal file
View File

@@ -0,0 +1,17 @@
import { createI18n } from 'vue-i18n'
import en from './en.json'
import zh from './zh.json'
const messages = {
en,
zh,
}
console.log(uni.getLocale())
const i18n = createI18n({
locale: 'zh',
messages,
})
export default i18n

3
src/locale/zh.json Normal file
View File

@@ -0,0 +1,3 @@
{
"app.name": "中文标题"
}

View File

@@ -1,12 +1,13 @@
import { createSSRApp } from 'vue'
import App from './App.vue'
import store from './store'
import i18n from './locale/index'
import 'virtual:svg-icons-register'
import 'virtual:uno.css'
export function createApp() {
const app = createSSRApp(App)
app.use(store)
app.use(store).use(i18n)
return {
app,
}

9
src/pages/index/i18n.vue Normal file
View File

@@ -0,0 +1,9 @@
<template>{{ $t('app.name') }}</template>
<route lang="json">
{
"style": {
"navigationBarTitleText": "%app.name%"
}
}
</route>

View File

@@ -2,8 +2,8 @@
<route lang="json5" type="home">
{
style: {
navigationStyle: 'custom',
navigationBarTitleText: '首页',
// "navigationStyle": "custom",
navigationBarTitleText: '%app.name%',
},
}
</route>
@@ -15,6 +15,7 @@
<view class="mt-12">
<image src="/static/logo.svg" alt="" class="w-40 h-40 block mx-auto" />
</view>
<view>{{ $t('app.name') }}</view>
<view class="text-center text-4xl main-title-color mt-8">unibest</view>
<view class="text-center text-2xl mt-2 mb-8">最好用的 uniapp 开发模板</view>
<view class="text-justify max-w-100 m-auto">