Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
4595542f
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,发现更多精彩内容 >>
提交
4595542f
编写于
9月 01, 2022
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' into alpha
上级
c3cd2073
1a09f753
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
122 addition
and
92 deletion
+122
-92
packages/uni-cli-shared/lib/preprocess.js
packages/uni-cli-shared/lib/preprocess.js
+17
-3
packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
...ni-template-compiler/__tests__/compiler-mp-alipay.spec.js
+17
-17
packages/uni-template-compiler/lib/template/generate.js
packages/uni-template-compiler/lib/template/generate.js
+52
-49
src/platforms/mp-alipay/runtime/wrapper/app-parser.js
src/platforms/mp-alipay/runtime/wrapper/app-parser.js
+0
-17
src/platforms/mp-alipay/runtime/wrapper/component-parser.js
src/platforms/mp-alipay/runtime/wrapper/component-parser.js
+29
-3
src/platforms/mp-toutiao/runtime/wrapper/component-parser.js
src/platforms/mp-toutiao/runtime/wrapper/component-parser.js
+4
-0
src/platforms/mp-toutiao/runtime/wrapper/page-parser.js
src/platforms/mp-toutiao/runtime/wrapper/page-parser.js
+0
-1
src/platforms/mp-toutiao/runtime/wrapper/util.js
src/platforms/mp-toutiao/runtime/wrapper/util.js
+3
-2
未找到文件。
packages/uni-cli-shared/lib/preprocess.js
浏览文件 @
4595542f
...
...
@@ -5,7 +5,10 @@ const DEFAULT_KEYS = [
'
APP
'
,
'
APP-PLUS-NVUE
'
,
'
APP-VUE
'
,
'
APP-NVUE
'
'
APP-NVUE
'
,
'
APP-ANDROID
'
,
'
APP-IOS
'
,
'
WEB
'
]
function
normalize
(
name
)
{
...
...
@@ -44,14 +47,25 @@ module.exports = function initPreprocess (name, platforms, userDefines = {}) {
nvueContext
.
APP_PLUS
=
true
nvueContext
.
APP_NVUE
=
true
nvueContext
.
APP_PLUS_NVUE
=
true
}
if
(
process
.
env
.
UNI_APP_PLATFORM
===
'
android
'
)
{
defaultContext
.
APP_ANDROID
=
true
}
else
if
(
process
.
env
.
UNI_APP_PLATFORM
===
'
ios
'
)
{
defaultContext
.
APP_IOS
=
true
}
else
{
defaultContext
.
APP_ANDROID
=
true
defaultContext
.
APP_IOS
=
true
}
}
if
(
name
===
'
h5
'
)
{
defaultContext
.
WEB
=
true
}
if
(
name
.
startsWith
(
'
mp-
'
))
{
vueContext
.
MP
=
true
}
if
(
name
.
startsWith
(
'
app-
'
))
{
vueContext
.
APP
=
true
vueContext
.
APP
=
true
nvueContext
.
APP
=
true
}
...
...
packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js
浏览文件 @
4595542f
...
...
@@ -31,11 +31,11 @@ describe('mp:compiler-mp-alipay', () => {
it
(
'
generate ref
'
,
()
=>
{
assertCodegen
(
'
<component1 ref="c1">text</component1>
'
,
'
<component1 vue-id="551070e6-1" ref="__r" data-ref="c1" onVueInit="__l">text</component1>
'
'
<component1 vue-id="551070e6-1" ref="__r" data-ref="c1" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"
>text</component1>
'
)
assertCodegen
(
'
<component1 :ref="c2">text<text>123213</text></component1>
'
,
'
<component1 vue-id="551070e6-1" ref="__r" data-ref="{{c2}}" onVueInit="__l">text<text>123213</text></component1>
'
'
<component1 vue-id="551070e6-1" ref="__r" data-ref="{{c2}}" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"
>text<text>123213</text></component1>
'
)
assertCodegen
(
'
<component1 v-for="item in items" ref="c3"></component1>
'
,
...
...
@@ -47,7 +47,7 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<component1>text</component1>
'
,
'
<component1 vue-id="551070e6-1" data-com-type="wx" ref="__r" onVueInit="__l">text</component1>
'
,
'
<component1 vue-id="551070e6-1" data-com-type="wx" ref="__r" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"
>text</component1>
'
,
undefined
,
undefined
,
{
...
...
@@ -56,7 +56,7 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<component1 @change="onChange" @cancle="onCancle">text</component1>
'
,
'
<component1 onChange="__e" onCancle="__e" vue-id="551070e6-1" data-event-opts="{{[[
\'
^change
\'
,[[
\'
onChange
\'
]]],[
\'
^cancle
\'
,[[
\'
onCancle
\'
]]]]}}" data-com-type="wx" ref="__r" data-event-list="onChange,onCancle" onVueInit="__l">text</component1>
'
,
'
<component1 onChange="__e" onCancle="__e" vue-id="551070e6-1" data-event-opts="{{[[
\'
^change
\'
,[[
\'
onChange
\'
]]],[
\'
^cancle
\'
,[[
\'
onCancle
\'
]]]]}}" data-com-type="wx" ref="__r" data-event-list="onChange,onCancle" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"
>text</component1>
'
,
undefined
,
undefined
,
{
...
...
@@ -65,7 +65,7 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<credit-pay @change="onChange" @cancle="onCancle">text</credit-pay>
'
,
'
<plugin-wrapper onChange="__e" onCancle="__e" vue-id="551070e6-1" onPluginWrap="__w" data-event-opts="{{[[
\'
^change
\'
,[[
\'
onChange
\'
]]],[
\'
^cancle
\'
,[[
\'
onCancle
\'
]]]]}}" data-com-type="wx" data-event-list="onChange,onCancle" onVueInit="__l"
><credit-pay onChange="{{
\'
onChange
\'
+
\'
551070e6-1
\'
}}" onCancle="{{
\'
onCancle
\'
+
\'
551070e6-1
\'
}}" onVueInit="__l
">text</credit-pay></plugin-wrapper>
'
,
'
<plugin-wrapper onChange="__e" onCancle="__e" vue-id="551070e6-1" onPluginWrap="__w" data-event-opts="{{[[
\'
^change
\'
,[[
\'
onChange
\'
]]],[
\'
^cancle
\'
,[[
\'
onCancle
\'
]]]]}}" data-com-type="wx" data-event-list="onChange,onCancle" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"><credit-pay onChange="{{
\'
onChange
\'
+
\'
551070e6-1
\'
}}" onCancle="{{
\'
onCancle
\'
+
\'
551070e6-1
\'
}}" onVueInit="__l" vue-slots="{{[
\'
default
\'
]}}
">text</credit-pay></plugin-wrapper>
'
,
undefined
,
undefined
,
{
...
...
@@ -82,33 +82,33 @@ describe('mp:compiler-mp-alipay', () => {
it
(
'
generate default slot
'
,
()
=>
{
assertCodegen
(
'
<component1>text</component1>
'
,
'
<component1 vue-id="551070e6-1" onVueInit="__l">text</component1>
'
'
<component1 vue-id="551070e6-1" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"
>text</component1>
'
)
assertCodegen
(
'
<component1>text<text>123213</text></component1>
'
,
'
<component1 vue-id="551070e6-1" onVueInit="__l">text<text>123213</text></component1>
'
'
<component1 vue-id="551070e6-1" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"
>text<text>123213</text></component1>
'
)
assertCodegen
(
'
<component1>text<block slot="right"></block></component1>
'
,
'
<component1 vue-id="551070e6-1" onVueInit="__l">text<view slot="right"></view></component1>
'
'
<component1 vue-id="551070e6-1" onVueInit="__l"
vue-slots="{{[
\'
default
\'
,
\'
right
\'
]}}"
>text<view slot="right"></view></component1>
'
)
})
it
(
'
generate scoped slot
'
,
()
=>
{
assertCodegen
(
'
<component1 :text="
\'
text
\'
"><template v-slot="props"><view :class="{text:props.text}">{{props.text}}</view></template></component1>
'
,
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l"><view slot-scope="props"><view class="{{((props.text)?
\'
text
\'
:
\'\'
)}}">{{props.text}}</view></view></component1>
'
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"
><view slot-scope="props"><view class="{{((props.text)?
\'
text
\'
:
\'\'
)}}">{{props.text}}</view></view></component1>
'
)
assertCodegen
(
'
<component1 :text="
\'
text
\'
"><template v-slot="{text}"><view :class="{text:text}">{{text}}</view></template></component1>
'
,
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l"><view slot-scope="__SCOPED__"><view class="{{((__SCOPED__.text)?
\'
text
\'
:
\'\'
)}}">{{__SCOPED__.text}}</view></view></component1>
'
'
<component1 vue-id="551070e6-1" text="text" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"
><view slot-scope="__SCOPED__"><view class="{{((__SCOPED__.text)?
\'
text
\'
:
\'\'
)}}">{{__SCOPED__.text}}</view></view></component1>
'
)
})
it
(
'
generate scoped slot with scopedSlotsCompiler: auto
'
,
()
=>
{
assertCodegen
(
'
<my-component><template v-slot="{item}">{{item}}<template></my-component>
'
,
'
<my-component vue-id="551070e6-1" onVueInit="__l"><view slot-scope="__SCOPED__">{{__SCOPED__.item}}</view></my-component>
'
,
'
<my-component vue-id="551070e6-1" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"
><view slot-scope="__SCOPED__">{{__SCOPED__.item}}</view></my-component>
'
,
'
with(this){}
'
,
{
scopedSlotsCompiler
:
'
auto
'
...
...
@@ -116,7 +116,7 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<my-component><template v-slot="{item}">{{getValue(item)}}<template></my-component>
'
,
'
<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" onVueInit="__l"><block a:if="{{$root.m0}}">{{$root.m1}}</block></my-component>
'
,
'
<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"
><block a:if="{{$root.m0}}">{{$root.m1}}</block></my-component>
'
,
'
with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default","item")):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}
'
,
{
scopedSlotsCompiler
:
'
auto
'
...
...
@@ -124,7 +124,7 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<my-component><template v-slot="item">{{getValue(item.text)}}<template></my-component>
'
,
'
<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" onVueInit="__l"><block a:if="{{$root.m0}}">{{$root.m1}}</block></my-component>
'
,
'
<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"
><block a:if="{{$root.m0}}">{{$root.m1}}</block></my-component>
'
,
'
with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default").text):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}
'
,
{
scopedSlotsCompiler
:
'
auto
'
...
...
@@ -207,7 +207,7 @@ describe('mp:compiler-mp-alipay', () => {
it
(
'
generate attrs with mergeVirtualHostAttributes
'
,
()
=>
{
assertCodegen
(
'
<custom-view>hello world</custom-view>
'
,
'
<custom-view vue-id="551070e6-1" onVueInit="__l" virtualHostStyle="{{virtualHostStyle}}" virtualHostClass="{{(virtualHostClass)}}">hello world</custom-view>
'
,
'
<custom-view vue-id="551070e6-1" onVueInit="__l" virtualHostStyle="{{virtualHostStyle}}" virtualHostClass="{{(virtualHostClass)}}"
vue-slots="{{[
\'
default
\'
]}}"
>hello world</custom-view>
'
,
'
with(this){}
'
,
{
mergeVirtualHostAttributes
:
true
...
...
@@ -215,7 +215,7 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<custom-view :class="class1" :style="style">hello world</custom-view>
'
,
'
<custom-view vue-id="551070e6-1" onVueInit="__l" virtualHostStyle="{{(style)+virtualHostStyle}}" virtualHostClass="{{((class1)+
\'
\'
+virtualHostClass)}}">hello world</custom-view>
'
,
'
<custom-view vue-id="551070e6-1" onVueInit="__l" virtualHostStyle="{{(style)+virtualHostStyle}}" virtualHostClass="{{((class1)+
\'
\'
+virtualHostClass)}}"
vue-slots="{{[
\'
default
\'
]}}"
>hello world</custom-view>
'
,
'
with(this){}
'
,
{
mergeVirtualHostAttributes
:
true
...
...
@@ -223,7 +223,7 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<view><custom-view>hello world</custom-view></view>
'
,
'
<view class="{{(virtualHostClass)}}" style="{{virtualHostStyle}}"><custom-view vue-id="551070e6-1" onVueInit="__l">hello world</custom-view></view>
'
,
'
<view class="{{(virtualHostClass)}}" style="{{virtualHostStyle}}"><custom-view vue-id="551070e6-1" onVueInit="__l"
vue-slots="{{[
\'
default
\'
]}}"
>hello world</custom-view></view>
'
,
'
with(this){}
'
,
{
mergeVirtualHostAttributes
:
true
...
...
@@ -231,7 +231,7 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen
(
'
<view><custom-view :class="class1" :style="style">hello world</custom-view></view>
'
,
'
<view class="{{(virtualHostClass)}}" style="{{virtualHostStyle}}"><custom-view vue-id="551070e6-1" onVueInit="__l" virtualHostStyle="{{(style)}}" virtualHostClass="{{(class1)}}">hello world</custom-view></view>
'
,
'
<view class="{{(virtualHostClass)}}" style="{{virtualHostStyle}}"><custom-view vue-id="551070e6-1" onVueInit="__l" virtualHostStyle="{{(style)}}" virtualHostClass="{{(class1)}}"
vue-slots="{{[
\'
default
\'
]}}"
>hello world</custom-view></view>
'
,
'
with(this){}
'
,
{
mergeVirtualHostAttributes
:
true
...
...
packages/uni-template-compiler/lib/template/generate.js
浏览文件 @
4595542f
...
...
@@ -46,61 +46,64 @@ function processElement (ast, state, isRoot) {
}
else
if
(
platformName
!==
'
mp-baidu
'
)
{
ast
.
attr
[
'
bind:
'
+
INTERNAL_EVENT_LINK
]
=
INTERNAL_EVENT_LINK
}
if
(
mergeVirtualHostAttributes
&&
platform
.
isComponent
(
ast
.
type
))
{
const
obj
=
{
style
:
VIRTUAL_HOST_STYLE
,
class
:
VIRTUAL_HOST_CLASS
}
Object
.
keys
(
obj
).
forEach
(
key
=>
{
if
(
key
in
ast
.
attr
)
{
ast
.
attr
[
obj
[
key
]]
=
ast
.
attr
[
key
]
// TODO 过滤小程序原生组件
{
// 处理自定义组件虚拟节点样式
if
(
mergeVirtualHostAttributes
)
{
const
obj
=
{
style
:
VIRTUAL_HOST_STYLE
,
class
:
VIRTUAL_HOST_CLASS
}
// 支付宝小程序自定义组件外部属性始终无效
if
(
platformName
===
'
mp-alipay
'
)
{
delete
ast
.
attr
[
key
]
Object
.
keys
(
obj
).
forEach
(
key
=>
{
if
(
key
in
ast
.
attr
)
{
ast
.
attr
[
obj
[
key
]]
=
ast
.
attr
[
key
]
}
// 支付宝小程序自定义组件外部属性始终无效
if
(
platformName
===
'
mp-alipay
'
)
{
delete
ast
.
attr
[
key
]
}
})
}
// 标记自定义组件插槽
const
children
=
ast
.
children
// default slot
let
defaultSlot
=
false
const
slots
=
[]
for
(
let
i
=
children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childElement
=
children
[
i
]
/**
* 仅百度、字节支持使用 block 作为命名插槽根节点
* 此处为了统一仅忽略默认插槽
* <block slot="left"></block> => <view slot="left"></view>
*/
if
(
typeof
childElement
!==
'
string
'
&&
childElement
.
attr
.
slot
)
{
const
slot
=
childElement
.
attr
.
slot
if
(
slot
&&
slot
!==
'
default
'
&&
childElement
.
type
===
'
block
'
)
{
childElement
.
type
=
'
view
'
}
slots
.
push
(
slot
)
}
else
{
defaultSlot
=
true
}
})
}
const
children
=
ast
.
children
// default slot
let
defaultSlot
=
false
const
slots
=
[]
for
(
let
i
=
children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childElement
=
children
[
i
]
/**
* 仅百度、字节支持使用 block 作为命名插槽根节点
* 此处为了统一仅忽略默认插槽
* <block slot="left"></block> => <view slot="left"></view>
*/
if
(
typeof
childElement
!==
'
string
'
&&
childElement
.
attr
.
slot
)
{
const
slot
=
childElement
.
attr
.
slot
if
(
slot
&&
slot
!==
'
default
'
&&
childElement
.
type
===
'
block
'
)
{
childElement
.
type
=
'
view
'
}
if
(
defaultSlot
)
{
slots
.
push
(
'
default
'
)
}
if
(
ast
.
attr
.
generic
)
{
Object
.
keys
(
ast
.
attr
.
generic
).
forEach
(
scopedSlotName
=>
{
slots
.
push
(
scopedSlotName
)
})
if
(
platformName
===
'
mp-toutiao
'
||
platformName
===
'
mp-lark
'
)
{
// 用于字节跳动|飞书小程序模拟抽象节点
ast
.
attr
.
generic
=
`{{
${
JSON
.
stringify
(
ast
.
attr
.
generic
)}
}}`
.
replace
(
/"/g
,
'
\'
'
)
}
else
{
delete
ast
.
attr
.
generic
}
slots
.
push
(
slot
)
}
else
{
defaultSlot
=
true
}
}
if
(
defaultSlot
)
{
slots
.
push
(
'
default
'
)
}
if
(
ast
.
attr
.
generic
)
{
Object
.
keys
(
ast
.
attr
.
generic
).
forEach
(
scopedSlotName
=>
{
slots
.
push
(
scopedSlotName
)
})
if
(
platformName
===
'
mp-toutiao
'
||
platformName
===
'
mp-lark
'
)
{
// 用于字节跳动|飞书小程序模拟抽象节点
ast
.
attr
.
generic
=
`{{
${
JSON
.
stringify
(
ast
.
attr
.
generic
)}
}}`
.
replace
(
/"/g
,
'
\'
'
)
}
else
{
delete
ast
.
attr
.
generic
if
(
slots
.
length
)
{
// 标记 slots
ast
.
attr
[
'
vue-slots
'
]
=
'
{{[
'
+
slots
.
reverse
().
map
(
slotName
=>
`'
${
slotName
}
'`
).
join
(
'
,
'
)
+
'
]}}
'
}
}
if
(
slots
.
length
&&
platformName
!==
'
mp-alipay
'
)
{
// 标记 slots
ast
.
attr
[
'
vue-slots
'
]
=
'
{{[
'
+
slots
.
reverse
().
map
(
slotName
=>
`'
${
slotName
}
'`
).
join
(
'
,
'
)
+
'
]}}
'
}
if
(
ast
.
attr
.
id
&&
ast
.
attr
.
id
.
indexOf
(
'
{{
'
)
===
0
)
{
state
.
tips
.
add
(
uniI18n
.
__
(
'
templateCompiler.idAttribNotAllowInCustomComponentProps
'
,
{
0
:
ast
.
type
}))
}
...
...
src/platforms/mp-alipay/runtime/wrapper/app-parser.js
浏览文件 @
4595542f
...
...
@@ -8,23 +8,6 @@ import {
}
from
'
./util
'
export
default
function
parseApp
(
vm
)
{
Object
.
defineProperty
(
Vue
.
prototype
,
'
$slots
'
,
{
get
()
{
return
this
.
$scope
&&
this
.
$scope
.
props
.
$slots
},
set
()
{
}
})
Object
.
defineProperty
(
Vue
.
prototype
,
'
$scopedSlots
'
,
{
get
()
{
return
this
.
$scope
&&
this
.
$scope
.
props
.
$scopedSlots
},
set
()
{
}
})
Vue
.
prototype
.
$onAliGetAuthorize
=
function
onAliGetAuthorize
(
method
,
$event
)
{
my
.
getPhoneNumber
({
success
:
(
res
)
=>
{
...
...
src/platforms/mp-alipay/runtime/wrapper/component-parser.js
浏览文件 @
4595542f
...
...
@@ -22,6 +22,29 @@ import {
initSpecialMethods
}
from
'
./util
'
function
initSlots
(
vm
,
vueSlots
)
{
const
$slots
=
Object
.
create
(
null
)
// 未启用小程序基础库 2.0 时,组件实例支持支持访问 $slots、$scopedSlots
Object
.
defineProperty
(
vm
,
'
$slots
'
,
{
get
()
{
const
$scope
=
this
.
$scope
return
(
$scope
&&
$scope
.
props
.
$slots
)
||
(
$scope
&&
$scope
.
props
.
$scopedSlots
?
{}
:
$slots
)
}
})
Object
.
defineProperty
(
vm
,
'
$scopedSlots
'
,
{
get
()
{
const
$scope
=
this
.
$scope
return
(
$scope
&&
$scope
.
props
.
$scopedSlots
)
||
(
$scope
&&
$scope
.
props
.
$slots
?
{}
:
$slots
)
}
})
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
if
(
Array
.
isArray
(
vueSlots
)
&&
vueSlots
.
length
)
{
vueSlots
.
forEach
(
slotName
=>
{
$slots
[
slotName
]
=
true
})
}
}
function
initVm
(
VueComponent
)
{
if
(
this
.
$vm
)
{
return
...
...
@@ -46,6 +69,8 @@ function initVm (VueComponent) {
// 初始化 vue 实例
this
.
$vm
=
new
VueComponent
(
options
)
initSlots
(
this
.
$vm
,
properties
.
vueSlots
)
// 触发首次 setData
this
.
$vm
.
$mount
()
}
else
{
...
...
@@ -61,6 +86,9 @@ function initVm (VueComponent) {
// 初始化 vue 实例
this
.
$vm
=
new
VueComponent
(
options
)
handleRef
.
call
(
options
.
parent
.
$scope
,
this
)
initSlots
(
this
.
$vm
,
properties
.
vueSlots
)
// 触发首次 setData
this
.
$vm
.
$mount
()
...
...
@@ -83,9 +111,7 @@ export default function parseComponent (vueComponentOptions) {
}
Object
.
keys
(
properties
).
forEach
(
key
=>
{
if
(
key
!==
'
vueSlots
'
)
{
props
[
key
]
=
properties
[
key
].
value
}
props
[
key
]
=
properties
[
key
].
value
})
const
componentOptions
=
{
...
...
src/platforms/mp-toutiao/runtime/wrapper/component-parser.js
浏览文件 @
4595542f
...
...
@@ -69,7 +69,11 @@ export default function parseComponent (vueOptions) {
})
}
const
oldDetached
=
lifetimes
.
detached
lifetimes
.
detached
=
function
detached
()
{
if
(
typeof
oldDetached
===
'
function
'
)
{
oldDetached
.
call
(
this
)
}
currentComponents
(
this
,
components
=>
{
const
index
=
components
.
indexOf
(
this
)
if
(
index
>=
0
)
{
...
...
src/platforms/mp-toutiao/runtime/wrapper/page-parser.js
浏览文件 @
4595542f
...
...
@@ -38,7 +38,6 @@ export default function parsePage (vuePageOptions) {
if
(
typeof
oldDetached
===
'
function
'
)
{
oldDetached
.
call
(
this
)
}
this
.
$vm
&&
this
.
$vm
.
$destroy
()
// 清理
const
webviewId
=
this
.
__webviewId__
webviewId
&&
Object
.
keys
(
instances
).
forEach
(
key
=>
{
...
...
src/platforms/mp-toutiao/runtime/wrapper/util.js
浏览文件 @
4595542f
...
...
@@ -16,12 +16,13 @@ export function initRefs (vm) {
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
get
()
{
const
$refs
=
{}
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
)
// mpInstance 销毁后 selectAllComponents 取值为 null
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
)
||
[]
components
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
$refs
[
ref
]
=
component
.
$vm
||
component
})
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
)
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
)
||
[]
forComponents
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
if
(
!
$refs
[
ref
])
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录