MCPcopy
hub / github.com/vuejs/composition-api / functionApiInit

Function functionApiInit

src/mixin.ts:48–85  ·  view source on GitHub ↗

* Vuex init hook, injected into each instances init hooks list.

(this: ComponentInstance)

Source from the content-addressed store, hash-verified

46 */
47
48 function functionApiInit(this: ComponentInstance) {
49 const vm = this
50 const $options = vm.$options
51 const { setup, render } = $options
52
53 if (render) {
54 // keep currentInstance accessible for createElement
55 $options.render = function (...args: any): any {
56 return activateCurrentInstance(toVue3ComponentInstance(vm), () =>
57 render.apply(this, args)
58 )
59 }
60 }
61
62 if (!setup) {
63 return
64 }
65 if (!isFunction(setup)) {
66 if (__DEV__) {
67 warn(
68 'The "setup" option should be a function that returns a object in component definitions.',
69 vm
70 )
71 }
72 return
73 }
74
75 const { data } = $options
76 // wrapper the data option, so we can invoke setup before data get resolved
77 $options.data = function wrappedData() {
78 initSetup(vm, vm.$props)
79 return isFunction(data)
80 ? (
81 data as (this: ComponentInstance, x: ComponentInstance) => object
82 ).call(vm, vm)
83 : data || {}
84 }
85 }
86
87 function initSetup(vm: ComponentInstance, props: Record<any, any> = {}) {
88 const setup = vm.$options.setup!

Callers

nothing calls this directly

Calls 5

activateCurrentInstanceFunction · 0.90
toVue3ComponentInstanceFunction · 0.90
isFunctionFunction · 0.90
warnFunction · 0.90
initSetupFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…