Skip to content

Commit

Permalink
fix: add slot v-bind warning (vuejs#6736)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamOne- authored and hefeng committed Jan 25, 2019
1 parent 105e040 commit 8c8eed9
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 8c8eed9

Please sign in to comment.