Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
23666102
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
718
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
23666102
编写于
7月 17, 2020
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 支持作用域插槽当作普通插槽使用(微信小程序、QQ小程序) question/98634
上级
bcecd71b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
30 addition
and
11 deletion
+30
-11
packages/uni-mp-weixin/lib/uni.compiler.js
packages/uni-mp-weixin/lib/uni.compiler.js
+15
-5
packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
...ni-template-compiler/__tests__/compiler-mp-weixin.spec.js
+10
-3
packages/uni-template-compiler/__tests__/compiler.spec.js
packages/uni-template-compiler/__tests__/compiler.spec.js
+2
-0
packages/uni-template-compiler/lib/template/traverse.js
packages/uni-template-compiler/lib/template/traverse.js
+3
-3
未找到文件。
packages/uni-mp-weixin/lib/uni.compiler.js
浏览文件 @
23666102
...
...
@@ -32,11 +32,21 @@ module.exports = {
state
.
componentGenerics
[
componentName
]
=
true
return
{
type
:
componentName
,
attr
:
props
||
{},
children
:
[]
}
// 返回多个节点,支持作用域插槽当作普通插槽使用
return
[
{
type
:
'
slot
'
,
attr
:
{
name
:
slotName
},
children
:
[]
},
{
type
:
componentName
,
attr
:
props
||
{},
children
:
[]
}
]
},
resolveScopedSlots
(
slotName
,
{
genCode
,
...
...
packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js
浏览文件 @
23666102
...
...
@@ -72,16 +72,23 @@ describe('mp:compiler-mp-weixin', () => {
})
it
(
'
generate scoped slot
'
,
()
=>
{
assertCodegen
(
'
<slot v-bind:user="user"></slot>
'
,
'
<slot></slot><scoped-slots-default user="{{user}}" bind:__l="__l"></scoped-slots-default>
'
,
function
(
res
)
{
expect
(
res
.
componentGenerics
[
'
scoped-slots-default
'
]).
toBe
(
true
)
}
)
assertCodegen
(
// TODO vue-id
'
<span><slot v-bind:user="user">{{ user.lastName }}</slot></span>
'
,
'
<label class="_span"><block wx:if="{{$slots.default}}"><scoped-slots-default user="{{user}}" bind:__l="__l"></scoped-slots-default></block><block wx:else>{{user.lastName}}</block></label>
'
,
'
<label class="_span"><block wx:if="{{$slots.default}}"><s
lot></slot><s
coped-slots-default user="{{user}}" bind:__l="__l"></scoped-slots-default></block><block wx:else>{{user.lastName}}</block></label>
'
,
function
(
res
)
{
expect
(
res
.
componentGenerics
[
'
scoped-slots-default
'
]).
toBe
(
true
)
}
)
assertCodegen
(
'
<span><slot name="header" v-bind:user="user">{{ user.lastName }}</slot></span>
'
,
'
<label class="_span"><block wx:if="{{$slots.header}}"><scoped-slots-header user="{{user}}" bind:__l="__l"></scoped-slots-header></block><block wx:else>{{user.lastName}}</block></label>
'
,
'
<label class="_span"><block wx:if="{{$slots.header}}"><s
lot name="header"></slot><s
coped-slots-header user="{{user}}" bind:__l="__l"></scoped-slots-header></block><block wx:else>{{user.lastName}}</block></label>
'
,
function
(
res
)
{
expect
(
res
.
componentGenerics
[
'
scoped-slots-header
'
]).
toBe
(
true
)
}
...
...
@@ -113,4 +120,4 @@ describe('mp:compiler-mp-weixin', () => {
'
<view><slot-comp generic:scoped-slots-test="test-slot-comp-test" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[
\'
test
\'
]}}"></slot-comp><slot-comp generic:scoped-slots-test="test-slot-comp-test1" vue-id="551070e6-2" bind:__l="__l" vue-slots="{{[
\'
test
\'
]}}"></slot-comp><slot-comp generic:scoped-slots-test="test-slot-comp-test2" vue-id="551070e6-3" bind:__l="__l" vue-slots="{{[
\'
test
\'
]}}"></slot-comp><slot-comp generic:scoped-slots-test="test-slot-comp-test3" vue-id="551070e6-4" bind:__l="__l" vue-slots="{{[
\'
test
\'
]}}"></slot-comp></view>
'
)
})
})
})
packages/uni-template-compiler/__tests__/compiler.spec.js
浏览文件 @
23666102
...
...
@@ -172,6 +172,8 @@ describe('mp:compiler', () => {
it
(
'
generate single slot
'
,
()
=>
{
assertCodegen
(
'
<view><slot></slot></view>
'
,
'
<view><slot></slot></view>
'
)
assertCodegen
(
'
<view><slot>default</slot></view>
'
,
'
<view><block wx:if="{{$slots.default}}"><slot></slot></block><block wx:else>default</block></view>
'
)
assertCodegen
(
'
<view><slot>{{hello}}</slot></view>
'
,
'
<view><block wx:if="{{$slots.default}}"><slot></slot></block><block wx:else>{{hello}}</block></view>
'
)
assertCodegen
(
'
<view><slot name="default"></slot></view>
'
,
'
<view><slot></slot></view>
'
)
})
...
...
packages/uni-template-compiler/lib/template/traverse.js
浏览文件 @
23666102
...
...
@@ -164,7 +164,7 @@ function traverseCreateElement (callExprNode, state) {
node
.
children
=
node
.
children
.
concat
(
normalizeChildren
(
traverseExpr
(
childNodes
,
state
)))
}
else
{
node
.
children
=
normalizeChildren
(
traverseExpr
(
childNodes
,
state
))
}
}
}
return
node
}
...
...
@@ -264,7 +264,7 @@ function genSlotNode (slotName, slotNode, fallbackNodes, state) {
attr
:
{
[
prefix
+
'
if
'
]:
'
{{$slots.
'
+
slotName
+
'
}}
'
},
children
:
[
slotNode
]
children
:
[
].
concat
(
slotNode
)
},
{
type
:
'
block
'
,
attr
:
{
...
...
@@ -461,4 +461,4 @@ function traverseCreateTextVNode (callExprNode, state) {
function
traverseCreateEmptyVNode
(
callExprNode
,
state
)
{
return
''
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录