Skip to content

Commit 514b90b

Browse files
jamOne-yyx990803
authored andcommitted
fix: add slot v-bind warning (#6736)
close #6677
1 parent db138e2 commit 514b90b

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/core/instance/render-helpers/render-slot.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import { extend, warn } from 'core/util/index'
3+
import { extend, warn, isObject } from 'core/util/index'
44

55
/**
66
* Runtime helper for rendering <slot>
@@ -15,6 +15,12 @@ export function renderSlot (
1515
if (scopedSlotFn) { // scoped slot
1616
props = props || {}
1717
if (bindObject) {
18+
if (process.env.NODE_ENV !== 'production' && !isObject(bindObject)) {
19+
warn(
20+
'slot v-bind without argument expects an Object',
21+
this
22+
)
23+
}
1824
props = extend(extend({}, bindObject), props)
1925
}
2026
return scopedSlotFn(props) || fallback

test/unit/features/component/component-scoped-slot.spec.js

+54
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,60 @@ describe('Component scoped slot', () => {
9393
}).then(done)
9494
})
9595

96+
it('should warn when using v-bind with no object', () => {
97+
new Vue({
98+
template: `
99+
<test ref="test">
100+
<template scope="props">
101+
</template>
102+
</test>
103+
`,
104+
components: {
105+
test: {
106+
data () {
107+
return {
108+
text: 'some text'
109+
}
110+
},
111+
template: `
112+
<div>
113+
<slot v-bind="text"></slot>
114+
</div>
115+
`
116+
}
117+
}
118+
}).$mount()
119+
expect('slot v-bind without argument expects an Object').toHaveBeenWarned()
120+
})
121+
122+
it('should not warn when using v-bind with object', () => {
123+
new Vue({
124+
template: `
125+
<test ref="test">
126+
<template scope="props">
127+
</template>
128+
</test>
129+
`,
130+
components: {
131+
test: {
132+
data () {
133+
return {
134+
foo: {
135+
text: 'some text'
136+
}
137+
}
138+
},
139+
template: `
140+
<div>
141+
<slot v-bind="foo"></slot>
142+
</div>
143+
`
144+
}
145+
}
146+
}).$mount()
147+
expect('slot v-bind without argument expects an Object').not.toHaveBeenWarned()
148+
})
149+
96150
it('named scoped slot', done => {
97151
const vm = new Vue({
98152
template: `

0 commit comments

Comments
 (0)