提交 99152119 编写于 作者: Q qiang

feat(mp-baidu): v-bind with scopedSlotsCompiler: legacy

上级 f43c0008
...@@ -8,9 +8,13 @@ module.exports = { ...@@ -8,9 +8,13 @@ module.exports = {
}, },
children: [] children: []
} }
Object.keys(props).forEach(name => { if (typeof props === 'string') {
node.attr['var-' + name] = props[name].replace('{{', '').replace('}}', '') node.attr['s-bind'] = props.replace('{{', '').replace('}}', '')
}) } else {
Object.keys(props).forEach(name => {
node.attr['var-' + name] = props[name].replace('{{', '').replace('}}', '')
})
}
return node return node
}, },
resolveScopedSlots (slotName, { resolveScopedSlots (slotName, {
...@@ -31,4 +35,4 @@ module.exports = { ...@@ -31,4 +35,4 @@ module.exports = {
} }
return node return node
} }
} }
...@@ -75,6 +75,10 @@ describe('mp:compiler-mp-baidu', () => { ...@@ -75,6 +75,10 @@ describe('mp:compiler-mp-baidu', () => {
'<span><slot name="header" v-bind:user="user">{{ user.lastName }}</slot></span>', '<span><slot name="header" v-bind:user="user">{{ user.lastName }}</slot></span>',
'<label class="_span"><block s-if="{{$slots.header}}"><slot name="header" var-user="user"></slot></block><block s-else>{{user.lastName}}</block></label>' '<label class="_span"><block s-if="{{$slots.header}}"><slot name="header" var-user="user"></slot></block><block s-else>{{user.lastName}}</block></label>'
) )
assertCodegen(
'<span><slot name="header" v-bind="user"></slot></span>',
'<label class="_span"><slot name="header" s-bind="user"></slot></label>'
)
}) })
it('generate scoped slot with scopedSlotsCompiler: auto', () => { it('generate scoped slot with scopedSlotsCompiler: auto', () => {
......
...@@ -306,9 +306,16 @@ function traverseRenderSlot (callExprNode, state) { ...@@ -306,9 +306,16 @@ function traverseRenderSlot (callExprNode, state) {
let deleteSlotName = false // 标记是否组件 slot 手动指定了 name="default" let deleteSlotName = false // 标记是否组件 slot 手动指定了 name="default"
if (state.options.scopedSlotsCompiler !== 'augmented' && callExprNode.arguments.length > 2) { // 作用域插槽 if (state.options.scopedSlotsCompiler !== 'augmented' && callExprNode.arguments.length > 2) { // 作用域插槽
const props = {} const props = {}
callExprNode.arguments[2].properties.forEach(property => { const arg2 = callExprNode.arguments[2]
props[property.key.value] = genCode(property.value) const arg3 = callExprNode.arguments[3]
}) let bindings
if (t.isObjectExpression(arg2)) {
arg2.properties.forEach(property => {
props[property.key.value] = genCode(property.value)
})
} else if (arg3) {
bindings = genCode(arg3)
}
deleteSlotName = props.SLOT_DEFAULT && Object.keys(props).length === 1 deleteSlotName = props.SLOT_DEFAULT && Object.keys(props).length === 1
if (!deleteSlotName) { if (!deleteSlotName) {
if (!isStaticSlotName) { if (!isStaticSlotName) {
...@@ -318,7 +325,7 @@ function traverseRenderSlot (callExprNode, state) { ...@@ -318,7 +325,7 @@ function traverseRenderSlot (callExprNode, state) {
delete props.SLOT_DEFAULT delete props.SLOT_DEFAULT
return genSlotNode( return genSlotNode(
slotName, slotName,
state.options.platform.createScopedSlots(slotName, props, state), state.options.platform.createScopedSlots(slotName, bindings || props, state),
callExprNode.arguments[1], callExprNode.arguments[1],
state state
) )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册