2021-10-06 12:37:45 +00:00
|
|
|
import Vue from 'vue'
|
2021-10-26 12:59:05 +00:00
|
|
|
import { createHooks } from 'hookable'
|
2021-10-11 17:48:03 +00:00
|
|
|
import { setNuxtAppInstance } from '#app'
|
2021-09-25 08:24:37 +00:00
|
|
|
|
|
|
|
export default (ctx, inject) => {
|
2021-10-18 18:31:37 +00:00
|
|
|
const nuxtApp = {
|
|
|
|
vueApp: {
|
2021-10-06 12:37:45 +00:00
|
|
|
component: Vue.component.bind(Vue),
|
|
|
|
config: {
|
|
|
|
globalProperties: {}
|
|
|
|
},
|
|
|
|
directive: Vue.directive.bind(Vue),
|
|
|
|
mixin: Vue.mixin.bind(Vue),
|
2021-10-26 12:59:05 +00:00
|
|
|
mount: () => { },
|
2021-10-06 12:37:45 +00:00
|
|
|
provide: inject,
|
2021-10-26 12:59:05 +00:00
|
|
|
unmount: () => { },
|
2021-11-02 09:45:44 +00:00
|
|
|
use (vuePlugin) {
|
2021-10-06 12:37:45 +00:00
|
|
|
vuePlugin.install(this)
|
|
|
|
},
|
|
|
|
version: Vue.version
|
|
|
|
},
|
2021-09-25 08:24:37 +00:00
|
|
|
provide: inject,
|
|
|
|
globalName: 'nuxt',
|
|
|
|
payload: process.client ? ctx.nuxtState : ctx.ssrContext.nuxt,
|
|
|
|
isHydrating: ctx.isHMR,
|
2021-10-18 18:31:37 +00:00
|
|
|
nuxt2Context: ctx
|
2021-09-25 08:24:37 +00:00
|
|
|
}
|
2021-10-06 12:37:45 +00:00
|
|
|
|
2021-10-18 18:31:37 +00:00
|
|
|
nuxtApp.hooks = createHooks()
|
|
|
|
nuxtApp.hook = nuxtApp.hooks.hook
|
|
|
|
nuxtApp.callHook = nuxtApp.hooks.callHook
|
2021-09-25 08:24:37 +00:00
|
|
|
|
|
|
|
if (!Array.isArray(ctx.app.created)) {
|
|
|
|
ctx.app.created = [ctx.app.created]
|
|
|
|
}
|
|
|
|
|
2021-10-06 12:37:45 +00:00
|
|
|
if (process.server) {
|
2021-10-18 18:31:37 +00:00
|
|
|
nuxtApp.ssrContext = ctx.ssrContext
|
2021-10-06 12:37:45 +00:00
|
|
|
}
|
|
|
|
|
2021-09-25 08:24:37 +00:00
|
|
|
ctx.app.created.push(function () {
|
2021-10-18 18:31:37 +00:00
|
|
|
nuxtApp.vue2App = this
|
2021-09-25 08:24:37 +00:00
|
|
|
})
|
|
|
|
|
2021-11-02 09:45:44 +00:00
|
|
|
const proxiedApp = new Proxy(nuxtApp, {
|
|
|
|
get (target, prop) {
|
|
|
|
if (prop[0] === '$') {
|
|
|
|
return target.nuxt2Context[prop] || target.vue2App?.[prop]
|
|
|
|
}
|
|
|
|
return Reflect.get(target, prop)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
setNuxtAppInstance(proxiedApp)
|
2021-09-25 08:24:37 +00:00
|
|
|
|
2021-11-02 09:45:44 +00:00
|
|
|
inject('_nuxtApp', proxiedApp)
|
2021-09-25 08:24:37 +00:00
|
|
|
}
|