diff --git a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
index 62278524de24b7b3fd0f1b5fbc23f4bc4118990b..64a623d1f7a5c07fc1d7b7db6df6e743195fec84 100644
--- a/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
+++ b/packages/uni-template-compiler/__tests__/compiler-app-plus-extra.view.spec.js
@@ -33,6 +33,12 @@ describe('codegen', () => {
'
A{{ d | e | f }}B{{text}}C
',
`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(
+ '',
+ `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 */
diff --git a/packages/uni-template-compiler/__tests__/demo.js b/packages/uni-template-compiler/__tests__/demo.js
index e4bea3e850ea0f23ab8db7c2719fb812a68cf512..2ac63bdadcaa15dd8a3f23ae65b480d827b07b84 100644
--- a/packages/uni-template-compiler/__tests__/demo.js
+++ b/packages/uni-template-compiler/__tests__/demo.js
@@ -1,7 +1,7 @@
const compiler = require('../lib')
const res = compiler.compile(
`
-
+
`, {
resourcePath: '/User/fxy/Documents/test.wxml',
isReservedTag: function (tag) {
diff --git a/packages/uni-template-compiler/lib/app/view.js b/packages/uni-template-compiler/lib/app/view.js
index 08b451f7322219d04bf6c24bac8b44e727495e73..5fce3ea1c188e4717198dfa6a7b6adc761965321 100644
--- a/packages/uni-template-compiler/lib/app/view.js
+++ b/packages/uni-template-compiler/lib/app/view.js
@@ -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')
//
// =>
//
@@ -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)
diff --git "a/src/platforms/app-plus/view/framework/plugins/\346\270\262\346\237\223.md" "b/src/platforms/app-plus/view/framework/plugins/\346\270\262\346\237\223.md"
deleted file mode 100644
index c435c7c0f50323551ba6b6d7f7c3759e758ad021..0000000000000000000000000000000000000000
--- "a/src/platforms/app-plus/view/framework/plugins/\346\270\262\346\237\223.md"
+++ /dev/null
@@ -1,25 +0,0 @@
-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