RainManGO / vue3-composition-admin

🎉 基于vue3 的管理端模板(Vue3 TS Vuex4 element-plus vue-i18n-next composition-api) vue3-admin vue3-ts-admin
MIT License
3.13k stars 913 forks source link

i18n相关的问题 #83

Open dybxin opened 3 years ago

dybxin commented 3 years ago

我有注意到你在permission.ts中定义的有如下代码:

// const getPageTitle = (key: string) => {
//   const i18n = useI18n()
//   const title = settings.title
//   const hasKey = i18n.te(`route.${key}`)
//   if (hasKey) {
//     const pageName = i18n.t(`route.${key}`)
//     return `${pageName} - ${title}`
//   }
//   return `${title}`
// }

我其实在vue-element-admin中的utils/get-page-title.js的基础上修改

import defaultSettings from '@/settings'
import i18n from'@/locales'

const title = defaultSettings.title || 'Vue3 Admin Template'

export default function getPageTitle(key) {
  const hasKey = i18n.te(`route.${key}`)
  if (hasKey) {
    const pageName = i18n.t(`route.${key}`)
    return `${pageName} - ${title}`
  }
  return `${title}`
}

遇到如下问题:

vue-router.esm-bundler.js?6c02:3248 TypeError: _locales__WEBPACK_IMPORTED_MODULE_2__.default.te is not a function
    at getPageTitle (get-page-title.js?036d:7)
    at _callee$ (permission.js?223d:19)
    at tryCatch (runtime.js?96cf:63)
    at Generator.invoke [as _invoke] (runtime.js?96cf:293)
    at Generator.eval [as next] (runtime.js?96cf:118)
    at asyncGeneratorStep (asyncToGenerator.js?1da1:3)
    at _next (asyncToGenerator.js?1da1:25)
    at eval (asyncToGenerator.js?1da1:32)
    at new Promise (<anonymous>)
    at eval (asyncToGenerator.js?1da1:21)