Skip to content

Commit 7d4e3fe

Browse files
authored
Merge pull request #1120 from Meituan-Dianping/develop
修复 slot 问题
2 parents 427fedd + ed2e02f commit 7d4e3fe

File tree

10 files changed

+170
-31
lines changed

10 files changed

+170
-31
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/Bug_report.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: 报告问题(Bug report)
3+
about: 描述你遇到的问题并寻求社区帮助
4+
---
5+
6+
## [问题简单描述]
7+
8+
**问题复现步骤:**
9+
10+
1. [第一步]
11+
2. [第二步]
12+
3. [其他步骤...]
13+
14+
**期望的表现:**
15+
16+
[在这里描述期望的表现]
17+
18+
**观察到的表现:**
19+
20+
[在这里描述观察到的表现]
21+
22+
**屏幕截图或动态图:**
23+
24+
![复现步骤的屏幕截图和动态 GIF 图](图片的 url)
25+
[建议提供可运行的demo]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
name: 建议新功能(Feature Request)
3+
about: 展示已经实现的新功能,或者对项目提出新的需求和建议
4+
---
5+
6+
## [在此简单描述您的建议]
7+
8+
**新功能相关的问题issue或讨论:**
9+
10+
[在这里引用新功能相关的讨论]
11+
12+
**新功能的实现:**
13+
14+
[在这里填写或简单描述功能的实现方式或需求的解决方式]
15+
16+
**相关项目或文档:**
17+
18+
[在这里引用相关项目或文档地址]

.github/issue_template.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
issueConfigs:
2+
-
3+
bannedTitle: "问题简单描述"
4+
subtitles:
5+
- "问题复现步骤:"
6+
- "期望的表现:"
7+
- "观察到的表现:"
8+
- "屏幕截图或动态图:"
9+
bannedContents:
10+
- "第一步"
11+
- "第二步"
12+
- "其他步骤..."
13+
- "在这里描述期望的表现"
14+
- "在这里描述观察到的表现"
15+
- "复现步骤的屏幕截图和动态 GIF 图"
16+
- "图片的 url",
17+
- "建议提供可运行的demo"
18+
-
19+
bannedTitle: "在此简单描述您的建议"
20+
subtitles:
21+
- "新功能相关的问题issue或讨论:"
22+
- "新功能的实现:"
23+
- "相关项目或文档:"
24+
bannedContents:
25+
- "在这里引用新功能相关的讨论"
26+
- "在这里填写或简单描述功能的实现方式或需求的解决方式"
27+
- "在这里引用相关项目或文档地址"
28+
29+
comments:
30+
closeIssue: "issue不符合格式要求,请确保格式正确且填写所有有效信息。\n请保留issue模板中的各级小标题(如“期望的表现:”),并使用有效信息替换模板默认内容(如“[在这里描述期望的表现]”)"

.github/stale.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
daysUntilStale: 30
2+
3+
markComment: "issue超过30天无更新或响应,7天后将自动关闭,如果问题状态有更新请及时更新issue"
4+
5+
limitPerRun: 24
6+
7+
only: issues

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,28 @@
9595
<img src="https://user-images.githubusercontent.com/6629280/42795085-e5fae9f8-89b4-11e8-9514-7764428be788.jpg" width="100" title="义乌购优选"/>
9696
<img src="https://camo.githubusercontent.com/9103a160806c94ed0e5787ee3b197159b3ba9f80/687474703a2f2f792e70686f746f2e71712e636f6d2f696d673f733d6a4456653262784862266c3d792e6a7067" width="100" title="熊猫斗图助手"/>
9797
<img src="https://user-images.githubusercontent.com/5915245/42990083-437e3072-8c34-11e8-8f6a-69ea58522be8.jpg" width="100" title="SPC运动宝"/>
98+
<img src="https://user-images.githubusercontent.com/5443058/42999490-9022a4dc-8c50-11e8-9e90-96bbc1bbbc8e.jpg" width="100" title="牛津阅读树点读版"/>
99+
<img src="https://camo.githubusercontent.com/c47426c0e0ad542f6399de4129682fed1f2b475c/68747470733a2f2f73312e617831782e636f6d2f323031382f30372f32312f50386f7368442e6a7067" width="100" title="花笙美妆"/>
100+
<img src="https://camo.githubusercontent.com/64ce4dd31ab2edc9f3a2f6f7dc943bd1dfaefa21/687474703a2f2f7063397034717362322e626b742e636c6f7564646e2e636f6d2f77782d6769746875622e6a7067" width="100" title="gitHub01"/>
101+
<img src="https://user-images.githubusercontent.com/15187909/43053228-29e08738-8e5e-11e8-8f91-377a28dcf771.jpg" width="100" title="极客教程"/>
102+
<img src="https://user-images.githubusercontent.com/7599915/43298816-425635f4-918a-11e8-9f0f-380dca9401dd.jpg" width="100" title="gitee工具"/>
103+
<img src="https://camo.githubusercontent.com/25a919d9549feb0b713ad86472c09e9c3f46aa83/687474703a2f2f696d616765732e70616e64616f6d656e672e636f6d2f32346665333339666662333936636662656238633136306435336261313539342e6a7067" width="100" title="销售神器"/>
104+
<img src="https://user-images.githubusercontent.com/17445000/43376242-3715ce48-93ec-11e8-90be-a59fe9788a98.jpg" width="100" title="360旗下-南瓜屋"/>
105+
<img src="https://user-images.githubusercontent.com/25244009/43445236-76c224be-94d8-11e8-9901-1ff399db7b70.jpg" width="100" title="地图小程序"/>
106+
<img src="https://user-images.githubusercontent.com/1448308/43559485-cbd41390-9640-11e8-848e-69b662be8da7.jpg" width="100" title="微工具书"/>
107+
<img src="https://user-images.githubusercontent.com/19870533/43562575-eed086f8-964f-11e8-8c39-20e604fd84fa.jpg" width="100" title="选课精灵"/>
108+
<img src="https://user-images.githubusercontent.com/13146991/43621850-f1df6730-970b-11e8-9d07-4db4f2c4c52f.png" width="100" title="京东云技术新知"/>
109+
<img src="https://user-images.githubusercontent.com/1627874/43621865-0df3a314-970c-11e8-8f1b-30cfdf6a9a47.jpg" width="100" title="运个货-互联网内贸集装箱海运物流平台"/>
110+
<img src="https://user-images.githubusercontent.com/4090027/44255554-0e352680-a239-11e8-96fe-8316a1fb22f8.jpg" width="100" title="小桔有车违章查询"/>
111+
<img src="https://user-images.githubusercontent.com/26808622/44326326-e1c61800-a48d-11e8-958f-d50ef7f45d62.png" width="100" title="餐饮,商超小程序"/>
112+
<img src="https://camo.githubusercontent.com/6f1b397785cd88ec260509e2768f10604b5711b9/687474703a2f2f7777772e77636c696d622e736974652f63646e2f7863782e6a7065673f763d31" width="100" title="妹子趣图"/>
113+
<img src="https://user-images.githubusercontent.com/12904977/44563258-02dd8000-a790-11e8-961d-fb50c4f27ba1.png" width="100" title="记工无忧"/>
114+
<img src="https://user-images.githubusercontent.com/22048131/44619692-5994a800-a8bd-11e8-98f0-b2337ef49b35.png" width="100" title="北美省钱快报App"/>
115+
98116
<!-- 非标准小程序码 -->
99117
<img src="https://user-images.githubusercontent.com/1176855/41755510-62b9fc90-760a-11e8-89be-b6ddbee08e63.jpg" width="100" title="暖茶阿妈的占卜小屋"/>
100118
<img src="https://user-images.githubusercontent.com/22720942/40184432-da33291c-5a22-11e8-966c-c836d1dc8078.png" width="100" />
119+
<img src="https://camo.githubusercontent.com/25b2636179cd939461975ada9f996c77d15c4d2a/68747470733a2f2f7778342e73696e61696d672e636e2f6d773639302f373032643563616167793166746e323975797a38666a323037363038367439612e6a7067" width="100" title="扫域名的小程序,米农帮"/>
101120
</div>
102121

103122
[贡献方法](./.github/CONTRIBUTING.md)

packages/mpvue-template-compiler/build.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4567,9 +4567,27 @@ function getSlotsName (obj) {
45674567
if (!obj) {
45684568
return ''
45694569
}
4570-
return Object.keys(obj).map(function (k) {
4571-
return ("$slot" + k + ":'" + (obj[k]) + "'")
4572-
}).join(',')
4570+
// wxml模板中 data="{{ a:{a1:'string2'}, b:'string'}}" 键a不能放在最后,会出错
4571+
return tmplateSlotsObj(obj)
4572+
.concat(
4573+
Object.keys(obj).map(function(k) {
4574+
return '$slot' + k + ":'" + obj[k] + "'"
4575+
})
4576+
)
4577+
.join(',')
4578+
}
4579+
4580+
function tmplateSlotsObj(obj) {
4581+
if (!obj) {
4582+
return []
4583+
}
4584+
// wxml模板中 data="{{ a:{a1:'string2'}, b:'string'}}" 键a1不能写成 'a1' 带引号的形式,会出错
4585+
var $for = Object.keys(obj)
4586+
.map(function(k) {
4587+
return (k + ":'" + (obj[k]) + "'")
4588+
})
4589+
.join(',');
4590+
return $for ? [("$for:{" + $for + "}")] : []
45734591
}
45744592

45754593
var component = {
@@ -4585,7 +4603,13 @@ var component = {
45854603
var slots = ast.slots;
45864604
if (slotName) {
45874605
attrsMap['data'] = "{{...$root[$k], $root}}";
4588-
attrsMap['is'] = "{{" + slotName + "}}";
4606+
// bindedName is available when rendering slot in v-for
4607+
var bindedName = attrsMap['v-bind:name'];
4608+
if(bindedName) {
4609+
attrsMap['is'] = "{{$for[" + bindedName + "]}}";
4610+
} else {
4611+
attrsMap['is'] = "{{" + slotName + "}}";
4612+
}
45894613
} else {
45904614
var slotsName = getSlotsName(slots);
45914615
var restSlotsName = slotsName ? (", " + slotsName) : '';

packages/mpvue/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4148,7 +4148,7 @@ Object.defineProperty(Vue$3.prototype, '$ssrContext', {
41484148
});
41494149

41504150
Vue$3.version = '2.4.1';
4151-
Vue$3.mpvueVersion = '1.0.12';
4151+
Vue$3.mpvueVersion = '1.0.13';
41524152

41534153
/* globals renderer */
41544154

src/platforms/mp/compiler/codegen/convert/component.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,27 @@ function getSlotsName (obj) {
22
if (!obj) {
33
return ''
44
}
5-
return Object.keys(obj).map(k => {
6-
return `$slot${k}:'${obj[k]}'`
7-
}).join(',')
5+
// wxml模板中 data="{{ a:{a1:'string2'}, b:'string'}}" 键a不能放在最后,会出错
6+
return tmplateSlotsObj(obj)
7+
.concat(
8+
Object.keys(obj).map(function(k) {
9+
return '$slot' + k + ":'" + obj[k] + "'"
10+
})
11+
)
12+
.join(',')
13+
}
14+
15+
function tmplateSlotsObj(obj) {
16+
if (!obj) {
17+
return []
18+
}
19+
// wxml模板中 data="{{ a:{a1:'string2'}, b:'string'}}" 键a1不能写成 'a1' 带引号的形式,会出错
20+
const $for = Object.keys(obj)
21+
.map(function(k) {
22+
return `${k}:'${obj[k]}'`
23+
})
24+
.join(',')
25+
return $for ? [`$for:{${$for}}`] : []
826
}
927

1028
export default {
@@ -14,8 +32,14 @@ export default {
1432
convertComponent (ast, components, slotName) {
1533
const { attrsMap, tag, mpcomid, slots } = ast
1634
if (slotName) {
17-
attrsMap['data'] = `{{...$root[$k], $root}}`
18-
attrsMap['is'] = `{{${slotName}}}`
35+
attrsMap['data'] = "{{...$root[$p], ...$root[$k], $root}}"
36+
// bindedName is available when rendering slot in v-for
37+
const bindedName = attrsMap['v-bind:name']
38+
if(bindedName) {
39+
attrsMap['is'] = "{{$for[" + bindedName + "]}}"
40+
} else {
41+
attrsMap['is'] = "{{" + slotName + "}}"
42+
}
1943
} else {
2044
const slotsName = getSlotsName(slots)
2145
const restSlotsName = slotsName ? `, ${slotsName}` : ''

test/mp/compiler/index.spec.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,20 @@ describe('slot', () => {
553553
)
554554
})
555555

556+
it('含`:name`的插槽组件', () => {
557+
assertCodegen(
558+
`<div><slot :name="tab.key">test</slot></div>`,
559+
`<template name="a"><view class="_div"><template name="default">test</template><template data="{{...$root[$k], $root}}" is="{{$for[tab.key]}}"></template></view></template>`,
560+
{
561+
name: 'a'
562+
}
563+
)
564+
})
565+
556566
it('slot name', () => {
557567
assertCodegen(
558568
`<card class="baz boo"><a slot="header">test</a></card>`,
559-
`<import src="/components/card" /><template name="a"><template data="{{...$root[$kk+'0'], $root, $slotdefault:'hashValue-default-0',$slotheader:'hashValue-header-0'}}" is="card"></template></template>`,
569+
`<import src="/components/card" /><template name="a"><template data="{{...$root[$kk+'0'], $root, $for:{default:'hashValue-default-0',header:'hashValue-header-0'},$slotdefault:'hashValue-default-0',$slotheader:'hashValue-header-0'}}" is="card"></template></template>`,
560570
{
561571
name: 'a',
562572
components: {
@@ -579,7 +589,7 @@ describe('slot', () => {
579589
it('slot template', () => {
580590
assertCodegen(
581591
`<card class="baz boo"><template slot="header">test</template></card>`,
582-
`<import src="/components/card" /><template name="a"><template data="{{...$root[$kk+'1'], $root, $slotdefault:'hashValue-default-1',$slotheader:'hashValue-header-1'}}" is="card"></template></template>`,
592+
`<import src="/components/card" /><template name="a"><template data="{{...$root[$kk+'1'], $root, $for:{default:'hashValue-default-1',header:'hashValue-header-1'},$slotdefault:'hashValue-default-1',$slotheader:'hashValue-header-1'}}" is="card"></template></template>`,
583593
{
584594
name: 'a',
585595
components: {
@@ -619,6 +629,7 @@ describe('slot', () => {
619629
)
620630
})
621631
})
632+
622633
describe('web-view', () => {
623634
it('web-view', () => {
624635
assertCodegen(

0 commit comments

Comments
 (0)