main.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import App from './App'
  2. import uviewPlus from '@/uni_modules/uview-plus'
  3. import store from './store/index.js'
  4. import {
  5. initRequest
  6. } from '@/config/request/index'
  7. import messages from './locale/index'
  8. import {
  9. route
  10. } from '@/uni_modules/uview-plus'
  11. let i18nConfig = {
  12. locale: uni.getLocale(),
  13. messages
  14. }
  15. // #ifndef VUE3
  16. import Vue from 'vue'
  17. import VueI18n from 'vue-i18n'
  18. Vue.use(VueI18n)
  19. // 全局混入 route 方法
  20. Vue.mixin({
  21. methods: {
  22. route(path) {
  23. route(path)
  24. }
  25. }
  26. })
  27. const vue2I18n = new VueI18n(i18nConfig)
  28. Vue.config.productionTip = false
  29. App.mpType = 'app'
  30. const app = new Vue({
  31. i18n: vue2I18n,
  32. ...App
  33. })
  34. app.$mount()
  35. // #endif
  36. // #ifdef VUE3
  37. import {
  38. createSSRApp
  39. } from 'vue'
  40. import {
  41. createI18n
  42. } from 'vue-i18n'
  43. const vue3I18n = createI18n(i18nConfig)
  44. export function createApp() {
  45. const app = createSSRApp(App)
  46. app.use(vue3I18n)
  47. app.use(uviewPlus)
  48. app.use(store)
  49. initRequest(app)
  50. // 添加全局方法
  51. app.config.globalProperties.$route = route
  52. // 添加全局混入
  53. app.mixin({
  54. methods: {
  55. $route(path) {
  56. route(path)
  57. }
  58. }
  59. })
  60. return {
  61. app
  62. }
  63. }
  64. // #endif