parent
71c3c6e2a0
commit
354d79c42b
@ -520,6 +520,17 @@ describe('api: options', () => {
|
|||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('render from mixin', () => {
|
||||||
|
const Comp = {
|
||||||
|
mixins: [
|
||||||
|
{
|
||||||
|
render: () => 'from mixin'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
expect(renderToString(h(Comp))).toBe('from mixin')
|
||||||
|
})
|
||||||
|
|
||||||
test('extends', () => {
|
test('extends', () => {
|
||||||
const calls: string[] = []
|
const calls: string[] = []
|
||||||
const Base = {
|
const Base = {
|
||||||
|
@ -589,6 +589,7 @@ function finishComponentSetup(
|
|||||||
instance.render = Component.render as InternalRenderFunction
|
instance.render = Component.render as InternalRenderFunction
|
||||||
}
|
}
|
||||||
} else if (!instance.render) {
|
} else if (!instance.render) {
|
||||||
|
// could be set from setup()
|
||||||
if (compile && Component.template && !Component.render) {
|
if (compile && Component.template && !Component.render) {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
startMeasure(instance, `compile`)
|
startMeasure(instance, `compile`)
|
||||||
@ -604,25 +605,6 @@ function finishComponentSetup(
|
|||||||
;(Component.render as InternalRenderFunction)._rc = true
|
;(Component.render as InternalRenderFunction)._rc = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__DEV__ && !Component.render) {
|
|
||||||
/* istanbul ignore if */
|
|
||||||
if (!compile && Component.template) {
|
|
||||||
warn(
|
|
||||||
`Component provided template option but ` +
|
|
||||||
`runtime compilation is not supported in this build of Vue.` +
|
|
||||||
(__ESM_BUNDLER__
|
|
||||||
? ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
|
|
||||||
: __ESM_BROWSER__
|
|
||||||
? ` Use "vue.esm-browser.js" instead.`
|
|
||||||
: __GLOBAL__
|
|
||||||
? ` Use "vue.global.js" instead.`
|
|
||||||
: ``) /* should not happen */
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
warn(`Component is missing template or render function.`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.render = (Component.render || NOOP) as InternalRenderFunction
|
instance.render = (Component.render || NOOP) as InternalRenderFunction
|
||||||
|
|
||||||
// for runtime-compiled render functions using `with` blocks, the render
|
// for runtime-compiled render functions using `with` blocks, the render
|
||||||
@ -642,6 +624,26 @@ function finishComponentSetup(
|
|||||||
applyOptions(instance, Component)
|
applyOptions(instance, Component)
|
||||||
currentInstance = null
|
currentInstance = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// warn missing template/render
|
||||||
|
if (__DEV__ && !Component.render && instance.render === NOOP) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (!compile && Component.template) {
|
||||||
|
warn(
|
||||||
|
`Component provided template option but ` +
|
||||||
|
`runtime compilation is not supported in this build of Vue.` +
|
||||||
|
(__ESM_BUNDLER__
|
||||||
|
? ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
|
||||||
|
: __ESM_BROWSER__
|
||||||
|
? ` Use "vue.esm-browser.js" instead.`
|
||||||
|
: __GLOBAL__
|
||||||
|
? ` Use "vue.global.js" instead.`
|
||||||
|
: ``) /* should not happen */
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
warn(`Component is missing template or render function.`)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const attrHandlers: ProxyHandler<Data> = {
|
const attrHandlers: ProxyHandler<Data> = {
|
||||||
|
@ -4,7 +4,8 @@ import {
|
|||||||
SetupContext,
|
SetupContext,
|
||||||
ComponentInternalOptions,
|
ComponentInternalOptions,
|
||||||
PublicAPIComponent,
|
PublicAPIComponent,
|
||||||
Component
|
Component,
|
||||||
|
InternalRenderFunction
|
||||||
} from './component'
|
} from './component'
|
||||||
import {
|
import {
|
||||||
isFunction,
|
isFunction,
|
||||||
@ -390,6 +391,7 @@ export function applyOptions(
|
|||||||
deactivated,
|
deactivated,
|
||||||
beforeUnmount,
|
beforeUnmount,
|
||||||
unmounted,
|
unmounted,
|
||||||
|
render,
|
||||||
renderTracked,
|
renderTracked,
|
||||||
renderTriggered,
|
renderTriggered,
|
||||||
errorCaptured
|
errorCaptured
|
||||||
@ -398,7 +400,10 @@ export function applyOptions(
|
|||||||
const publicThis = instance.proxy!
|
const publicThis = instance.proxy!
|
||||||
const ctx = instance.ctx
|
const ctx = instance.ctx
|
||||||
const globalMixins = instance.appContext.mixins
|
const globalMixins = instance.appContext.mixins
|
||||||
// call it only during dev
|
|
||||||
|
if (asMixin && render && instance.render === NOOP) {
|
||||||
|
instance.render = render as InternalRenderFunction
|
||||||
|
}
|
||||||
|
|
||||||
// applyOptions is called non-as-mixin once per instance
|
// applyOptions is called non-as-mixin once per instance
|
||||||
if (!asMixin) {
|
if (!asMixin) {
|
||||||
@ -406,6 +411,7 @@ export function applyOptions(
|
|||||||
// global mixins are applied first
|
// global mixins are applied first
|
||||||
applyMixins(instance, globalMixins, deferredData, deferredWatch)
|
applyMixins(instance, globalMixins, deferredData, deferredWatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// extending a base component...
|
// extending a base component...
|
||||||
if (extendsOptions) {
|
if (extendsOptions) {
|
||||||
applyOptions(instance, extendsOptions, deferredData, deferredWatch, true)
|
applyOptions(instance, extendsOptions, deferredData, deferredWatch, true)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user