mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-02 12:07:39 +08:00
revert: feat: expose all scoped slots on this.$slots
This reverts commit 0129b0eb12
.
This commit is contained in:
parent
7bc88f30c3
commit
d5ade28652
@ -1,6 +1,5 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
|
|
||||||
import { hasOwn } from 'shared/util'
|
|
||||||
import { def } from 'core/util/lang'
|
import { def } from 'core/util/lang'
|
||||||
import { normalizeChildren } from 'core/vdom/helpers/normalize-children'
|
import { normalizeChildren } from 'core/vdom/helpers/normalize-children'
|
||||||
|
|
||||||
@ -17,7 +16,7 @@ export function normalizeScopedSlots (
|
|||||||
res = {}
|
res = {}
|
||||||
for (const key in slots) {
|
for (const key in slots) {
|
||||||
if (slots[key] && key[0] !== '$') {
|
if (slots[key] && key[0] !== '$') {
|
||||||
res[key] = normalizeScopedSlot(normalSlots, key, slots[key])
|
res[key] = normalizeScopedSlot(slots[key])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,20 +31,13 @@ export function normalizeScopedSlots (
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeScopedSlot(normalSlots, key, fn) {
|
function normalizeScopedSlot(fn: Function): Function {
|
||||||
const normalized = (scope = {}) => {
|
return scope => {
|
||||||
const res = fn(scope)
|
const res = fn(scope)
|
||||||
return res && typeof res === 'object' && !Array.isArray(res)
|
return res && typeof res === 'object' && !Array.isArray(res)
|
||||||
? [res] // single vnode
|
? [res] // single vnode
|
||||||
: normalizeChildren(res)
|
: normalizeChildren(res)
|
||||||
}
|
}
|
||||||
// proxy scoped slots on normal $slots
|
|
||||||
if (!hasOwn(normalSlots, key)) {
|
|
||||||
Object.defineProperty(normalSlots, key, {
|
|
||||||
get: normalized
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return normalized
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function proxyNormalSlot(slots, key) {
|
function proxyNormalSlot(slots, key) {
|
||||||
|
@ -456,7 +456,7 @@ describe('Component scoped slot', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// new in 2.6, unifying all slots as functions
|
// new in 2.6, unifying all slots as functions
|
||||||
it('non-scoped slots should also be available on this.$scopedSlots', () => {
|
it('non-scoped slots should also be available on $scopedSlots', () => {
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: `<foo>before <div slot="bar" slot-scope="scope">{{ scope.msg }}</div> after</foo>`,
|
template: `<foo>before <div slot="bar" slot-scope="scope">{{ scope.msg }}</div> after</foo>`,
|
||||||
components: {
|
components: {
|
||||||
@ -473,24 +473,6 @@ describe('Component scoped slot', () => {
|
|||||||
expect(vm.$el.innerHTML).toBe(`before after<div>hi</div>`)
|
expect(vm.$el.innerHTML).toBe(`before after<div>hi</div>`)
|
||||||
})
|
})
|
||||||
|
|
||||||
// #9421 the other side of unification is also needed
|
|
||||||
// for library authors
|
|
||||||
it('scoped slots should also be available on this.$slots', () => {
|
|
||||||
const Child = {
|
|
||||||
render: function (h) {
|
|
||||||
return h(
|
|
||||||
'div',
|
|
||||||
this.$slots.content
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const vm = new Vue({
|
|
||||||
template: `<child><template #content>foo</template></child>`,
|
|
||||||
components: { Child }
|
|
||||||
}).$mount()
|
|
||||||
expect(vm.$el.innerHTML).toBe(`foo`)
|
|
||||||
})
|
|
||||||
|
|
||||||
// #4779
|
// #4779
|
||||||
it('should support dynamic slot target', done => {
|
it('should support dynamic slot target', done => {
|
||||||
const Child = {
|
const Child = {
|
||||||
|
Loading…
Reference in New Issue
Block a user