index.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import Vue from 'vue'
  2. import Meta from 'vue-meta'
  3. import ClientOnly from 'vue-client-only'
  4. import NoSsr from 'vue-no-ssr'
  5. import { createRouter } from './router.js'
  6. import NuxtChild from './components/nuxt-child.js'
  7. import NuxtError from './components/nuxt-error.vue'
  8. import Nuxt from './components/nuxt.js'
  9. import App from './App.js'
  10. import { setContext, getLocation, getRouteData, normalizeError } from './utils'
  11. /* Plugins */
  12. import nuxt_plugin_plugin_1e727d58 from 'nuxt_plugin_plugin_1e727d58' // Source: .\\components\\plugin.js (mode: 'all')
  13. // Component: <ClientOnly>
  14. Vue.component(ClientOnly.name, ClientOnly)
  15. // TODO: Remove in Nuxt 3: <NoSsr>
  16. Vue.component(NoSsr.name, {
  17. ...NoSsr,
  18. render (h, ctx) {
  19. if (process.client && !NoSsr._warned) {
  20. NoSsr._warned = true
  21. console.warn('<no-ssr> has been deprecated and will be removed in Nuxt 3, please use <client-only> instead')
  22. }
  23. return NoSsr.render(h, ctx)
  24. }
  25. })
  26. // Component: <NuxtChild>
  27. Vue.component(NuxtChild.name, NuxtChild)
  28. Vue.component('NChild', NuxtChild)
  29. // Component NuxtLink is imported in server.js or client.js
  30. // Component: <Nuxt>
  31. Vue.component(Nuxt.name, Nuxt)
  32. Object.defineProperty(Vue.prototype, '$nuxt', {
  33. get() {
  34. const globalNuxt = this.$root.$options.$nuxt
  35. if (process.client && !globalNuxt && typeof window !== 'undefined') {
  36. return window.$nuxt
  37. }
  38. return globalNuxt
  39. },
  40. configurable: true
  41. })
  42. Vue.use(Meta, {"keyName":"head","attribute":"data-n-head","ssrAttribute":"data-n-head-ssr","tagIDKeyName":"hid"})
  43. const defaultTransition = {"name":"page","mode":"out-in","appear":false,"appearClass":"appear","appearActiveClass":"appear-active","appearToClass":"appear-to"}
  44. async function createApp(ssrContext, config = {}) {
  45. const router = await createRouter(ssrContext, config)
  46. // Create Root instance
  47. // here we inject the router and store to all child components,
  48. // making them available everywhere as `this.$router` and `this.$store`.
  49. const app = {
  50. head: {"title":"caimei-authentic-website","htmlAttrs":{"lang":"en"},"meta":[{"charset":"utf-8"},{"name":"keywords","content":"ross、西班牙ross、ross智能体疗、云智能体疗、ross产康、ross美容"},{"hid":"description","name":"description","content":"西班牙ROSS坚持创新45年,专注人体健康发展、致力于免疫力提升,为您的健康保驾护航,助你更美更健康!"},{"name":"viewport","content":"width=device-width, initial-scale=1"},{"name":"format-detection","content":"telephone=no"},{"name":"viewport","content":"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"}],"link":[{"rel":"icon","type":"image\u002Fx-icon","href":"\u002Ffavicon.ico"},{"rel":"stylesheet","href":"\u002Flibs\u002Fswiper\u002Fswiper.min.css"}],"script":[{"src":"\u002Flibs\u002Fjquery-3.6.0.min.js"},{"src":"\u002Flibs\u002Fswiper\u002Fswiper.min.js"},{"src":"\u002Fjs\u002Fmain.js"}],"style":[]},
  51. router,
  52. nuxt: {
  53. defaultTransition,
  54. transitions: [defaultTransition],
  55. setTransitions (transitions) {
  56. if (!Array.isArray(transitions)) {
  57. transitions = [transitions]
  58. }
  59. transitions = transitions.map((transition) => {
  60. if (!transition) {
  61. transition = defaultTransition
  62. } else if (typeof transition === 'string') {
  63. transition = Object.assign({}, defaultTransition, { name: transition })
  64. } else {
  65. transition = Object.assign({}, defaultTransition, transition)
  66. }
  67. return transition
  68. })
  69. this.$options.nuxt.transitions = transitions
  70. return transitions
  71. },
  72. err: null,
  73. dateErr: null,
  74. error (err) {
  75. err = err || null
  76. app.context._errored = Boolean(err)
  77. err = err ? normalizeError(err) : null
  78. let nuxt = app.nuxt // to work with @vue/composition-api, see https://github.com/nuxt/nuxt.js/issues/6517#issuecomment-573280207
  79. if (this) {
  80. nuxt = this.nuxt || this.$options.nuxt
  81. }
  82. nuxt.dateErr = Date.now()
  83. nuxt.err = err
  84. // Used in src/server.js
  85. if (ssrContext) {
  86. ssrContext.nuxt.error = err
  87. }
  88. return err
  89. }
  90. },
  91. ...App
  92. }
  93. const next = ssrContext ? ssrContext.next : location => app.router.push(location)
  94. // Resolve route
  95. let route
  96. if (ssrContext) {
  97. route = router.resolve(ssrContext.url).route
  98. } else {
  99. const path = getLocation(router.options.base, router.options.mode)
  100. route = router.resolve(path).route
  101. }
  102. // Set context to app.context
  103. await setContext(app, {
  104. route,
  105. next,
  106. error: app.nuxt.error.bind(app),
  107. payload: ssrContext ? ssrContext.payload : undefined,
  108. req: ssrContext ? ssrContext.req : undefined,
  109. res: ssrContext ? ssrContext.res : undefined,
  110. beforeRenderFns: ssrContext ? ssrContext.beforeRenderFns : undefined,
  111. ssrContext
  112. })
  113. function inject(key, value) {
  114. if (!key) {
  115. throw new Error('inject(key, value) has no key provided')
  116. }
  117. if (value === undefined) {
  118. throw new Error(`inject('${key}', value) has no value provided`)
  119. }
  120. key = '$' + key
  121. // Add into app
  122. app[key] = value
  123. // Add into context
  124. if (!app.context[key]) {
  125. app.context[key] = value
  126. }
  127. // Check if plugin not already installed
  128. const installKey = '__nuxt_' + key + '_installed__'
  129. if (Vue[installKey]) {
  130. return
  131. }
  132. Vue[installKey] = true
  133. // Call Vue.use() to install the plugin into vm
  134. Vue.use(() => {
  135. if (!Object.prototype.hasOwnProperty.call(Vue.prototype, key)) {
  136. Object.defineProperty(Vue.prototype, key, {
  137. get () {
  138. return this.$root.$options[key]
  139. }
  140. })
  141. }
  142. })
  143. }
  144. // Inject runtime config as $config
  145. inject('config', config)
  146. // Add enablePreview(previewData = {}) in context for plugins
  147. if (process.static && process.client) {
  148. app.context.enablePreview = function (previewData = {}) {
  149. app.previewData = Object.assign({}, previewData)
  150. inject('preview', previewData)
  151. }
  152. }
  153. // Plugin execution
  154. if (typeof nuxt_plugin_plugin_1e727d58 === 'function') {
  155. await nuxt_plugin_plugin_1e727d58(app.context, inject)
  156. }
  157. // Lock enablePreview in context
  158. if (process.static && process.client) {
  159. app.context.enablePreview = function () {
  160. console.warn('You cannot call enablePreview() outside a plugin.')
  161. }
  162. }
  163. // Wait for async component to be resolved first
  164. await new Promise((resolve, reject) => {
  165. // Ignore 404s rather than blindly replacing URL in browser
  166. if (process.client) {
  167. const { route } = router.resolve(app.context.route.fullPath)
  168. if (!route.matched.length) {
  169. return resolve()
  170. }
  171. }
  172. router.replace(app.context.route.fullPath, resolve, (err) => {
  173. // https://github.com/vuejs/vue-router/blob/v3.4.3/src/util/errors.js
  174. if (!err._isRouter) return reject(err)
  175. if (err.type !== 2 /* NavigationFailureType.redirected */) return resolve()
  176. // navigated to a different route in router guard
  177. const unregister = router.afterEach(async (to, from) => {
  178. if (process.server && ssrContext && ssrContext.url) {
  179. ssrContext.url = to.fullPath
  180. }
  181. app.context.route = await getRouteData(to)
  182. app.context.params = to.params || {}
  183. app.context.query = to.query || {}
  184. unregister()
  185. resolve()
  186. })
  187. })
  188. })
  189. return {
  190. app,
  191. router
  192. }
  193. }
  194. export { createApp, NuxtError }