Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
秃秃的瑾
uni-app
提交
3e06ae95
U
uni-app
项目概览
秃秃的瑾
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3e06ae95
编写于
8月 24, 2022
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp-toutiao): 修复反复快速创建销毁页面时组件无法渲染的问题
上级
399b2a7f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
64 addition
and
28 deletion
+64
-28
src/platforms/mp-toutiao/runtime/wrapper/component-parser.js
src/platforms/mp-toutiao/runtime/wrapper/component-parser.js
+34
-13
src/platforms/mp-toutiao/runtime/wrapper/page-parser.js
src/platforms/mp-toutiao/runtime/wrapper/page-parser.js
+28
-14
src/platforms/mp-toutiao/runtime/wrapper/util.js
src/platforms/mp-toutiao/runtime/wrapper/util.js
+2
-1
未找到文件。
src/platforms/mp-toutiao/runtime/wrapper/component-parser.js
浏览文件 @
3e06ae95
import
{
isPage
,
initRelation
,
handleLink
handleLink
,
components
}
from
'
./util
'
import
{
...
...
@@ -11,17 +12,26 @@ import {
import
parseBaseComponent
from
'
../../../mp-weixin/runtime/wrapper/component-base-parser
'
const
components
=
[]
function
currentComponents
(
mpInstance
,
callback
)
{
const
webviewId
=
mpInstance
.
__webviewId__
const
currentComponents
=
components
[
webviewId
]
if
(
currentComponents
)
{
callback
(
currentComponents
)
}
}
export
default
function
parseComponent
(
vueOptions
)
{
const
[
componentOptions
,
VueComponent
]
=
parseBaseComponent
(
vueOptions
)
const
lifetimes
=
componentOptions
.
lifetimes
// 基础库 2.0 以上 attached 顺序错乱,按照 created 顺序强制纠正
componentOptions
.
lifetimes
.
created
=
function
created
()
{
components
.
push
(
this
)
lifetimes
.
created
=
function
created
()
{
currentComponents
(
this
,
components
=>
{
components
.
push
(
this
)
})
}
componentOptions
.
lifetimes
.
attached
=
function
attached
()
{
lifetimes
.
attached
=
function
attached
()
{
this
.
__lifetimes_attached
=
function
()
{
const
properties
=
this
.
properties
...
...
@@ -48,17 +58,28 @@ export default function parseComponent (vueOptions) {
// 触发首次 setData
this
.
$vm
.
$mount
()
}
let
component
=
this
while
(
component
&&
component
.
__lifetimes_attached
&&
components
[
0
]
&&
component
===
components
[
0
])
{
components
.
shift
()
component
.
__lifetimes_attached
()
delete
component
.
__lifetimes_attached
component
=
components
[
0
]
}
currentComponents
(
this
,
components
=>
{
let
component
=
this
while
(
component
&&
component
.
__lifetimes_attached
&&
components
[
0
]
&&
component
===
components
[
0
])
{
components
.
shift
()
component
.
__lifetimes_attached
()
delete
component
.
__lifetimes_attached
component
=
components
[
0
]
}
})
}
lifetimes
.
detached
=
function
detached
()
{
currentComponents
(
this
,
components
=>
{
const
index
=
components
.
indexOf
(
this
)
if
(
index
>=
0
)
{
components
.
splice
(
index
,
1
)
}
})
}
// ready 比 handleLink 还早,初始化逻辑放到 handleLink 中
delete
componentOptions
.
lifetimes
.
ready
delete
lifetimes
.
ready
componentOptions
.
methods
.
__l
=
handleLink
...
...
src/platforms/mp-toutiao/runtime/wrapper/page-parser.js
浏览文件 @
3e06ae95
import
{
isPage
,
isPage
,
instances
,
components
,
initRelation
}
from
'
./util
'
...
...
@@ -11,8 +12,17 @@ export default function parsePage (vuePageOptions) {
isPage
,
initRelation
})
const
lifetimes
=
pageOptions
.
lifetimes
const
oldCreated
=
lifetimes
.
created
lifetimes
.
created
=
function
created
()
{
const
webviewId
=
this
.
__webviewId__
components
[
webviewId
]
=
[]
if
(
typeof
oldCreated
===
'
function
'
)
{
oldCreated
.
call
(
this
)
}
}
// 页面需要在 ready 中触发,其他组件是在 handleLink 中触发
pageOptions
.
lifetimes
.
ready
=
function
ready
()
{
lifetimes
.
ready
=
function
ready
()
{
if
(
this
.
$vm
&&
this
.
$vm
.
mpType
===
'
page
'
)
{
this
.
$vm
.
__call_hook
(
'
created
'
)
this
.
$vm
.
__call_hook
(
'
beforeMount
'
)
...
...
@@ -22,18 +32,22 @@ export default function parsePage (vuePageOptions) {
}
else
{
this
.
is
&&
console
.
warn
(
this
.
is
+
'
is not ready
'
)
}
}
pageOptions
.
lifetimes
.
detached
=
function
detached
()
{
this
.
$vm
&&
this
.
$vm
.
$destroy
()
// 清理
const
webviewId
=
this
.
__webviewId__
webviewId
&&
Object
.
keys
(
instances
).
forEach
(
key
=>
{
if
(
key
.
indexOf
(
webviewId
+
'
_
'
)
===
0
)
{
delete
instances
[
key
]
}
})
}
const
oldDetached
=
lifetimes
.
detached
lifetimes
.
detached
=
function
detached
()
{
if
(
typeof
oldDetached
===
'
function
'
)
{
oldDetached
.
call
(
this
)
}
this
.
$vm
&&
this
.
$vm
.
$destroy
()
// 清理
const
webviewId
=
this
.
__webviewId__
webviewId
&&
Object
.
keys
(
instances
).
forEach
(
key
=>
{
if
(
key
.
indexOf
(
webviewId
+
'
_
'
)
===
0
)
{
delete
instances
[
key
]
}
})
delete
components
[
webviewId
]
}
return
pageOptions
}
}
src/platforms/mp-toutiao/runtime/wrapper/util.js
浏览文件 @
3e06ae95
...
...
@@ -52,6 +52,7 @@ export function initRefs (vm) {
}
export
const
instances
=
Object
.
create
(
null
)
export
const
components
=
Object
.
create
(
null
)
export
function
initRelation
({
vuePid
,
...
...
@@ -101,4 +102,4 @@ export function handleLink ({
vm
.
_isMounted
=
true
vm
.
__call_hook
(
'
mounted
'
)
vm
.
__call_hook
(
'
onReady
'
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录