Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
陈庄旺
uni-app
提交
c7449882
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,发现更多精彩内容 >>
提交
c7449882
编写于
3月 19, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(runtime): 调整 onLoad 顺序
上级
272f581d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
99 addition
and
53 deletion
+99
-53
packages/uni-app-plus/dist/index.js
packages/uni-app-plus/dist/index.js
+74
-47
src/core/runtime/wrapper/create-page.js
src/core/runtime/wrapper/create-page.js
+4
-6
src/platforms/app-plus/runtime/wrapper/index.js
src/platforms/app-plus/runtime/wrapper/index.js
+21
-0
未找到文件。
packages/uni-app-plus/dist/index.js
浏览文件 @
c7449882
...
@@ -301,9 +301,20 @@ function getData (vueOptions) {
...
@@ -301,9 +301,20 @@ function getData (vueOptions) {
console
.
warn
(
'
根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。
'
,
data
);
console
.
warn
(
'
根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。
'
,
data
);
}
}
}
}
}
else
{
try
{
// 对 data 格式化
data
=
JSON
.
parse
(
JSON
.
stringify
(
data
));
}
catch
(
e
)
{}
}
}
return
Object
.
assign
(
data
,
methods
)
Object
.
keys
(
methods
).
forEach
(
methodName
=>
{
if
(
!
hasOwn
(
data
,
methodName
))
{
data
[
methodName
]
=
methods
[
methodName
];
}
});
return
data
}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
...
@@ -317,7 +328,21 @@ function createObserver (name) {
...
@@ -317,7 +328,21 @@ function createObserver (name) {
}
}
function
getProperties
(
props
)
{
function
getProperties
(
props
)
{
const
properties
=
{};
const
properties
=
{
vueSlots
:
{
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
type
:
null
,
value
:
[],
observer
:
function
(
newVal
,
oldVal
)
{
const
$slots
=
Object
.
create
(
null
);
newVal
.
forEach
(
slotName
=>
{
$slots
[
slotName
]
=
true
;
});
this
.
setData
({
$slots
});
}
}
};
if
(
Array
.
isArray
(
props
))
{
// ['title']
if
(
Array
.
isArray
(
props
))
{
// ['title']
props
.
forEach
(
key
=>
{
props
.
forEach
(
key
=>
{
properties
[
key
]
=
{
properties
[
key
]
=
{
...
@@ -419,10 +444,6 @@ function handleEvent (event) {
...
@@ -419,10 +444,6 @@ function handleEvent (event) {
});
});
}
}
function
handleLink
(
event
)
{
event
.
detail
.
$parent
=
this
.
$vm
;
}
function
initRefs
(
vm
)
{
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
...
@@ -444,20 +465,6 @@ function initRefs (vm) {
...
@@ -444,20 +465,6 @@ function initRefs (vm) {
return
$refs
return
$refs
}
}
});
});
}
function
initChildren
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
Object
.
defineProperty
(
vm
,
'
$children
'
,
{
get
()
{
const
$children
=
[];
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-com
'
);
components
.
forEach
(
component
=>
{
$children
.
push
(
component
.
$vm
);
});
return
$children
}
});
}
}
const
hooks
=
[
const
hooks
=
[
...
@@ -486,8 +493,11 @@ function createApp (vueOptions) {
...
@@ -486,8 +493,11 @@ function createApp (vueOptions) {
if
(
this
.
mpType
!==
'
app
'
)
{
if
(
this
.
mpType
!==
'
app
'
)
{
initRefs
(
this
);
initRefs
(
this
);
initMocks
(
this
);
initMocks
(
this
);
initChildren
(
this
);
}
}
},
created
()
{
// 处理 injections
this
.
__init_injections
(
this
);
this
.
__init_provide
(
this
);
}
}
});
});
...
@@ -510,6 +520,28 @@ function createApp (vueOptions) {
...
@@ -510,6 +520,28 @@ function createApp (vueOptions) {
return
vueOptions
return
vueOptions
}
}
function
triggerLink
(
mpInstance
,
vueOptions
)
{
mpInstance
.
triggerEvent
(
'
__l
'
,
mpInstance
.
$vm
||
vueOptions
,
{
bubbles
:
true
,
composed
:
true
});
}
function
handleLink
(
event
)
{
if
(
event
.
detail
.
$mp
)
{
// vm
if
(
!
event
.
detail
.
$parent
)
{
event
.
detail
.
$parent
=
this
.
$vm
;
event
.
detail
.
$parent
.
$children
.
push
(
event
.
detail
);
event
.
detail
.
$root
=
this
.
$vm
.
$root
;
}
}
else
{
// vueOptions
if
(
!
event
.
detail
.
parent
)
{
event
.
detail
.
parent
=
this
.
$vm
;
}
}
}
const
hooks$1
=
[
const
hooks$1
=
[
'
onShow
'
,
'
onShow
'
,
'
onHide
'
,
'
onHide
'
,
...
@@ -537,11 +569,12 @@ function createPage (vueOptions) {
...
@@ -537,11 +569,12 @@ function createPage (vueOptions) {
mpInstance
:
this
mpInstance
:
this
}));
}));
this
.
$vm
.
__call_hook
(
'
created
'
);
this
.
$vm
.
__call_hook
(
'
onLoad
'
,
args
);
// 开发者一般可能会在 onLoad 时赋值,所以提前到 mount 之前
this
.
$vm
.
$mount
();
this
.
$vm
.
$mount
();
this
.
$vm
.
__call_hook
(
'
onLoad
'
,
args
);
},
},
onReady
()
{
onReady
()
{
this
.
$vm
.
_isMounted
=
true
;
this
.
$vm
.
_isMounted
=
true
;
this
.
$vm
.
__call_hook
(
'
mounted
'
);
this
.
$vm
.
__call_hook
(
'
mounted
'
);
this
.
$vm
.
__call_hook
(
'
onReady
'
);
this
.
$vm
.
__call_hook
(
'
onReady
'
);
},
},
...
@@ -560,21 +593,28 @@ function createPage (vueOptions) {
...
@@ -560,21 +593,28 @@ function createPage (vueOptions) {
return
Page
(
pageOptions
)
return
Page
(
pageOptions
)
}
}
function
initVueComponent
(
mpInstace
,
VueComponent
)
{
function
initVueComponent
(
mpInstace
,
VueComponent
,
extraOptions
=
{})
{
if
(
mpInstace
.
$vm
)
{
if
(
mpInstace
.
$vm
)
{
return
return
}
}
const
options
=
{
const
options
=
Object
.
assign
(
{
mpType
:
'
component
'
,
mpType
:
'
component
'
,
mpInstance
:
mpInstace
,
mpInstance
:
mpInstace
,
propsData
:
mpInstace
.
properties
propsData
:
mpInstace
.
properties
};
}
,
extraOptions
)
;
// 初始化 vue 实例
// 初始化 vue 实例
mpInstace
.
$vm
=
new
VueComponent
(
options
);
mpInstace
.
$vm
=
new
VueComponent
(
options
);
// 初始化渲染数据
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
mpInstace
.
$vm
.
$mount
();
const
vueSlots
=
mpInstace
.
properties
.
vueSlots
;
if
(
Array
.
isArray
(
vueSlots
)
&&
vueSlots
.
length
)
{
const
$slots
=
Object
.
create
(
null
);
vueSlots
.
forEach
(
slotName
=>
{
$slots
[
slotName
]
=
true
;
});
mpInstace
.
$vm
.
$scopedSlots
=
mpInstace
.
$vm
.
$slots
=
$slots
;
}
}
}
function
createComponent
(
vueOptions
)
{
function
createComponent
(
vueOptions
)
{
...
@@ -597,24 +637,11 @@ function createComponent (vueOptions) {
...
@@ -597,24 +637,11 @@ function createComponent (vueOptions) {
},
},
ready
()
{
ready
()
{
initVueComponent
(
this
,
VueComponent
);
// 目前发现部分情况小程序 attached 不触发
initVueComponent
(
this
,
VueComponent
);
// 目前发现部分情况小程序 attached 不触发
triggerLink
(
this
);
// 处理 parent,children
{
// 初始化渲染数据(需要等 parent,inject 都初始化完成,否则可以放到 attached 里边初始化渲染)
this
.
triggerEvent
(
'
__l
'
,
this
.
$vm
);
// TODO 百度仅能传递 json 对象
this
.
$vm
.
__call_hook
(
'
created
'
);
}
this
.
$vm
.
$mount
();
const
eventId
=
this
.
dataset
.
eventId
;
if
(
eventId
)
{
const
listeners
=
this
.
$vm
.
$parent
.
$mp
.
listeners
;
if
(
listeners
)
{
const
listenerOpts
=
listeners
[
eventId
];
Object
.
keys
(
listenerOpts
).
forEach
(
eventType
=>
{
listenerOpts
[
eventType
].
forEach
(
handler
=>
{
this
.
$vm
[
handler
.
once
?
'
$once
'
:
'
$on
'
](
eventType
,
handler
);
});
});
}
}
this
.
$vm
.
_isMounted
=
true
;
this
.
$vm
.
_isMounted
=
true
;
this
.
$vm
.
__call_hook
(
'
mounted
'
);
this
.
$vm
.
__call_hook
(
'
mounted
'
);
this
.
$vm
.
__call_hook
(
'
onReady
'
);
this
.
$vm
.
__call_hook
(
'
onReady
'
);
...
@@ -628,10 +655,10 @@ function createComponent (vueOptions) {
...
@@ -628,10 +655,10 @@ function createComponent (vueOptions) {
this
.
$vm
.
__call_hook
(
'
onPageShow
'
,
args
);
this
.
$vm
.
__call_hook
(
'
onPageShow
'
,
args
);
},
},
hide
()
{
hide
()
{
this
.
$vm
.
__call_hook
(
'
onPageHide
'
);
this
.
$vm
&&
this
.
$vm
.
__call_hook
(
'
onPageHide
'
);
},
},
resize
(
size
)
{
resize
(
size
)
{
this
.
$vm
.
__call_hook
(
'
onPageResize
'
,
size
);
this
.
$vm
&&
this
.
$vm
.
__call_hook
(
'
onPageResize
'
,
size
);
}
}
},
},
methods
:
{
methods
:
{
...
...
src/core/runtime/wrapper/create-page.js
浏览文件 @
c7449882
...
@@ -39,13 +39,11 @@ export function createPage (vueOptions) {
...
@@ -39,13 +39,11 @@ export function createPage (vueOptions) {
this
.
$vm
=
new
Vue
(
Object
.
assign
(
vueOptions
,
{
this
.
$vm
=
new
Vue
(
Object
.
assign
(
vueOptions
,
{
mpType
:
'
page
'
,
mpType
:
'
page
'
,
mpInstance
:
this
mpInstance
:
this
}))
}))
this
.
$vm
.
__call_hook
(
'
created
'
)
this
.
$vm
.
__call_hook
(
'
created
'
)
this
.
$vm
.
__call_hook
(
'
onLoad
'
,
args
)
// 开发者一般可能会在 onLoad 时赋值,所以提前到 mount 之前
this
.
$vm
.
$mount
()
this
.
$vm
.
$mount
()
this
.
$vm
.
__call_hook
(
'
onLoad
'
,
args
)
},
},
onReady
()
{
onReady
()
{
this
.
$vm
.
_isMounted
=
true
this
.
$vm
.
_isMounted
=
true
...
...
src/platforms/app-plus/runtime/wrapper/index.js
0 → 100644
浏览文件 @
c7449882
export
function
triggerLink
(
mpInstance
,
vueOptions
)
{
mpInstance
.
triggerEvent
(
'
__l
'
,
mpInstance
.
$vm
||
vueOptions
,
{
bubbles
:
true
,
composed
:
true
})
}
export
function
handleLink
(
event
)
{
if
(
event
.
detail
.
$mp
)
{
// vm
if
(
!
event
.
detail
.
$parent
)
{
event
.
detail
.
$parent
=
this
.
$vm
event
.
detail
.
$parent
.
$children
.
push
(
event
.
detail
)
event
.
detail
.
$root
=
this
.
$vm
.
$root
}
}
else
{
// vueOptions
if
(
!
event
.
detail
.
parent
)
{
event
.
detail
.
parent
=
this
.
$vm
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录