Skip to content

Commit 126a199

Browse files
committed
百度小程序模板语法适配
1 parent a83d817 commit 126a199

File tree

5 files changed

+29
-30
lines changed

5 files changed

+29
-30
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default {
2-
if: 'wx:if',
3-
iterator1: 'wx:for-index',
4-
key: 'wx:key',
5-
alias: 'wx:for-item',
6-
'v-for': 'wx:for'
2+
// 'if': 's-if',
3+
'v-for': 's-for',
4+
'alias': 's-for-item',
5+
'iterator1': 's-for-index',
6+
'key': 's-key'
77
}

src/platforms/mp/compiler/codegen-swan/config/wxmlDirectiveMap.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const noSupport = {
1515
}
1616
export default {
1717
'v-if': {
18-
name: 'wx:if',
19-
type: 0
18+
name: 's-if',
19+
type: 2
2020
},
2121
'v-else-if': {
22-
name: 'wx:elif',
23-
type: 0
22+
name: 's-elif',
23+
type: 2
2424
},
2525
'v-else': {
26-
name: 'wx:else',
26+
name: 'w-else',
2727
type: 1
2828
},
2929
'v-text': {

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ function getSlotsName (obj) {
55
// wxml模板中 data="{{ a:{a1:'string2'}, b:'string'}}" 键a不能放在最后,会出错
66
return tmplateSlotsObj(obj)
77
.concat(
8-
Object.keys(obj).map(function(k) {
9-
return '$slot' + k + ":'" + obj[k] + "'"
10-
})
8+
Object.keys(obj).map(k => `$slot${k}:'${obj[k]}'`)
119
)
1210
.join(',')
1311
}
@@ -18,9 +16,7 @@ function tmplateSlotsObj(obj) {
1816
}
1917
// wxml模板中 data="{{ a:{a1:'string2'}, b:'string'}}" 键a1不能写成 'a1' 带引号的形式,会出错
2018
const $for = Object.keys(obj)
21-
.map(function(k) {
22-
return `${k}:'${obj[k]}'`
23-
})
19+
.map(k => `${k}:'${obj[k]}'`)
2420
.join(',')
2521
return $for ? [`$for:{${$for}}`] : []
2622
}
@@ -32,7 +28,7 @@ export default {
3228
convertComponent (ast, components, slotName) {
3329
const { attrsMap, tag, mpcomid, slots } = ast
3430
if (slotName) {
35-
attrsMap['data'] = "{{...$root[$k], $root}}"
31+
attrsMap['data'] = "{{{...$root[$k], $root}}}"
3632
// bindedName is available when rendering slot in v-for
3733
const bindedName = attrsMap['v-bind:name']
3834
if(bindedName) {
@@ -43,7 +39,7 @@ export default {
4339
} else {
4440
const slotsName = getSlotsName(slots)
4541
const restSlotsName = slotsName ? `, ${slotsName}` : ''
46-
attrsMap['data'] = `{{...$root[$kk+${mpcomid}], $root${restSlotsName}}}`
42+
attrsMap['data'] = `{{{...$root[$kk+${mpcomid}], $root${restSlotsName}}}}`
4743
attrsMap['is'] = components[tag].name
4844
}
4945
return ast

src/platforms/mp/compiler/codegen-swan/convert/for.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@ import astMap from '../config/astMap'
33
export default function (ast) {
44
const { iterator1, for: forText, key, alias, attrsMap } = ast
55

6-
if (forText) {
7-
attrsMap[astMap['v-for']] = `{{${forText}}}`
8-
if (iterator1) {
9-
attrsMap[astMap['iterator1']] = iterator1
10-
}
11-
if (key) {
12-
attrsMap[astMap['key']] = key
13-
}
14-
if (alias) {
15-
attrsMap[astMap['alias']] = alias
16-
}
6+
// 缩写:<view s-for="p,index in persons">
7+
// 全写:<view s-for="persons" s-for-index="index" s-for-item="p">
178

9+
if (forText) {
10+
attrsMap[astMap['v-for']] = `${alias},${iterator1} in ${forText}`
11+
// attrsMap[astMap['v-for']] = forText
12+
// if (iterator1) {
13+
// attrsMap[astMap['iterator1']] = iterator1
14+
// }
15+
// if (alias) {
16+
// attrsMap[astMap['alias']] = alias
17+
// }
18+
// if (key) {
19+
// attrsMap[astMap['key']] = key
20+
// }
1821
delete attrsMap['v-for']
1922
}
2023

24+
2125
return ast
2226
}

src/platforms/mp/compiler/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import codeGenWx from './codegen/index'
66
import codeGenSwan from './codegen-swan/index'
77

88
function compileToWxml (compiled, options, fileExt) {
9-
debugger
109
let code
1110
switch(fileExt.platform) {
1211
case 'swan':

0 commit comments

Comments
 (0)