Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChenYFan_OHHH
uni-app
提交
13e58408
U
uni-app
项目概览
ChenYFan_OHHH
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
13e58408
编写于
10月 19, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(v3): improve slot logic
上级
8af6afcf
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
28 addition
and
36 deletion
+28
-36
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
...e-compiler/__tests__/compiler-app-plus-extra.view.spec.js
+6
-0
packages/uni-template-compiler/__tests__/demo.js
packages/uni-template-compiler/__tests__/demo.js
+1
-1
packages/uni-template-compiler/lib/app/view.js
packages/uni-template-compiler/lib/app/view.js
+21
-9
src/platforms/app-plus/view/framework/plugins/渲染.md
src/platforms/app-plus/view/framework/plugins/渲染.md
+0
-26
未找到文件。
packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
浏览文件 @
13e58408
...
...
@@ -33,6 +33,12 @@ describe('codegen', () => {
'
<div>A{{ d | e | f }}B{{text}}C</div>
'
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v("A"+(_$g(0,'t0'))+"B"+(_$g(0,'t1'))+"C")])}`
)
})
it
(
'
generate slot fallback content
'
,
()
=>
{
assertCodegen
(
'
<div><slot><div>{{hi}}</div></slot></div>
'
,
`with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_t("default",[_c('v-uni-view',{attrs:{"_i":2}},[_v((_$g(2,'t0',1)))])],{"_i":1})],2)}`
)
})
})
/* eslint-enable quotes */
packages/uni-template-compiler/__tests__/demo.js
浏览文件 @
13e58408
const
compiler
=
require
(
'
../lib
'
)
const
res
=
compiler
.
compile
(
`
<div><
template v-for="item in items"><span v-if="item.sub"></span></template
></div>
<div><
slot><div>{{hi}}</div></slot
></div>
`
,
{
resourcePath
:
'
/User/fxy/Documents/test.wxml
'
,
isReservedTag
:
function
(
tag
)
{
...
...
packages/uni-template-compiler/lib/app/view.js
浏览文件 @
13e58408
...
...
@@ -16,23 +16,35 @@ const parseComponent = require('./parser/component-parser')
const
basePreTransformNode
=
require
(
'
./pre-transform-node
'
)
function
createGenVar
(
id
)
{
function
createGenVar
(
id
,
isInSlot
=
false
)
{
return
function
genVar
(
name
,
extra
=
''
)
{
const
isFallbackContent
=
isInSlot
?
'
,1
'
:
''
extra
=
extra
?
(
'
,
'
+
extra
)
:
''
return
`
${
DATA_ROOT
}
(
${
id
}
,'
${
name
}
'
${
extra
}
)`
return
`
${
DATA_ROOT
}
(
${
id
}
,'
${
name
}
'
${
isFallbackContent
}${
extra
}
)`
}
}
function
isInSlot
(
el
)
{
let
parent
=
el
.
parent
while
(
parent
)
{
if
(
parent
.
tag
===
'
slot
'
)
{
return
true
}
parent
=
parent
.
parent
}
return
false
}
// if 使用该方案是因为 template 节点之类无法挂靠 extras
function
processIfConditions
(
el
)
{
if
(
el
.
if
)
{
el
.
ifConditions
.
forEach
(
con
=>
{
if
(
isVar
(
con
.
exp
))
{
con
.
exp
=
createGenVar
(
con
.
block
.
attrsMap
[
ID
])(
con
.
block
.
elseif
?
'
v-else-if
'
:
'
v-if
'
)
con
.
exp
=
createGenVar
(
con
.
block
.
attrsMap
[
ID
]
,
isInSlot
(
el
)
)(
con
.
block
.
elseif
?
'
v-else-if
'
:
'
v-if
'
)
}
})
el
.
if
=
createGenVar
(
el
.
attrsMap
[
ID
])(
'
v-if
'
)
el
.
if
=
createGenVar
(
el
.
attrsMap
[
ID
]
,
isInSlot
(
el
)
)(
'
v-if
'
)
}
}
...
...
@@ -48,7 +60,7 @@ function processBinding (el, genVar) {
function
processFor
(
el
,
genVal
)
{
if
(
el
.
for
&&
isVar
(
el
.
for
))
{
el
.
for
=
createGenVar
(
el
.
forId
)(
'
v-for
'
)
el
.
for
=
createGenVar
(
el
.
forId
,
isInSlot
(
el
)
)(
'
v-for
'
)
// <div><li v-for=" { a, b } in items"></li></div>
// =>
// <div><li v-for="$item in items"></li></div>
...
...
@@ -75,7 +87,7 @@ function processKey (el) {
el
.
key
=
`
${
forEl
.
alias
}
['k
${
keyIndex
}
']`
}
}
else
{
isVar
(
el
.
key
)
&&
(
el
.
key
=
createGenVar
(
el
.
attrsMap
[
ID
])(
'
a-key
'
))
isVar
(
el
.
key
)
&&
(
el
.
key
=
createGenVar
(
el
.
attrsMap
[
ID
]
,
isInSlot
(
el
)
)(
'
a-key
'
))
}
}
}
...
...
@@ -109,8 +121,8 @@ function processText (el, parent) {
const
state
=
{
index
:
0
,
view
:
true
,
genVar
:
createGenVar
(
parent
.
attrsMap
[
ID
])
}
genVar
:
createGenVar
(
parent
.
attrsMap
[
ID
]
,
isInSlot
(
parent
)
)
}
// fixed by xxxxxx 注意:保持平台一致性,trim 一下
el
.
expression
=
parseText
(
el
.
text
.
trim
(),
false
,
state
).
expression
}
...
...
@@ -127,7 +139,7 @@ function transformNode (el, parent, state) {
}
const
id
=
el
.
attrsMap
[
ID
]
const
genVar
=
createGenVar
(
id
)
const
genVar
=
createGenVar
(
id
,
isInSlot
(
el
)
)
processFor
(
el
,
genVar
)
processKey
(
el
)
...
...
src/platforms/app-plus/view/framework/plugins/渲染.md
已删除
100644 → 0
浏览文件 @
8af6afcf
1.
service new VuePageComponent
2.
service beforeCreate nodeId
3.
service page mounted send first data
first render
//第一次渲染,
//1.需要带有页面 id,页面路径等
//2.首次渲染的 nodeId 列表
//3.数据
//二次渲染
//1.新增的 nodeId
//2.数据
[
[init,[pageId,{}]],
[created,['1','2']],
[mounted,[['1',{}],['2',{}]]]
]
//首次处理流程
//1.接收到命令后,创建 vd
//2.创建页面 vm,beforeCreate 中赋值页面数据,赋值 nodeId
//二次处理流程
//1.接收到命令后,根据 nodeId 查找 vm,存在,则赋值+forceUpdate,
即 beforeCreate 中提取 nodeId,
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录