Skip to content

Commit

Permalink
fix: add slot v-bind warning (#6736)
Browse files Browse the repository at this point in the history
close #6677
  • Loading branch information
jamOne- authored and yyx990803 committed Oct 6, 2017
1 parent db138e2 commit 514b90b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/core/instance/render-helpers/render-slot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import { extend, warn } from 'core/util/index'
import { extend, warn, isObject } from 'core/util/index'

/**
* Runtime helper for rendering <slot>
Expand All @@ -15,6 +15,12 @@ export function renderSlot (
if (scopedSlotFn) { // scoped slot
props = props || {}
if (bindObject) {
if (process.env.NODE_ENV !== 'production' && !isObject(bindObject)) {
warn(
'slot v-bind without argument expects an Object',
this
)
}
props = extend(extend({}, bindObject), props)
}
return scopedSlotFn(props) || fallback
Expand Down
54 changes: 54 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,60 @@ describe('Component scoped slot', () => {
}).then(done)
})

it('should warn when using v-bind with no object', () => {
new Vue({
template: `
<test ref="test">
<template scope="props">
</template>
</test>
`,
components: {
test: {
data () {
return {
text: 'some text'
}
},
template: `
<div>
<slot v-bind="text"></slot>
</div>
`
}
}
}).$mount()
expect('slot v-bind without argument expects an Object').toHaveBeenWarned()
})

it('should not warn when using v-bind with object', () => {
new Vue({
template: `
<test ref="test">
<template scope="props">
</template>
</test>
`,
components: {
test: {
data () {
return {
foo: {
text: 'some text'
}
}
},
template: `
<div>
<slot v-bind="foo"></slot>
</div>
`
}
}
}).$mount()
expect('slot v-bind without argument expects an Object').not.toHaveBeenWarned()
})

it('named scoped slot', done => {
const vm = new Vue({
template: `
Expand Down

0 comments on commit 514b90b

Please sign in to comment.