Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
一个豆瓣
uni-app
提交
947050b6
U
uni-app
项目概览
一个豆瓣
/
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,发现更多精彩内容 >>
提交
947050b6
编写于
11月 03, 2022
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mp): MPComponent skip deep observe
上级
b98183ff
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
54 addition
and
19 deletion
+54
-19
packages/vue-cli-plugin-uni/packages/mp-vue/dist/mp.runtime.esm.js
...vue-cli-plugin-uni/packages/mp-vue/dist/mp.runtime.esm.js
+3
-2
src/platforms/mp-alipay/runtime/index.js
src/platforms/mp-alipay/runtime/index.js
+2
-1
src/platforms/mp-alipay/runtime/wrapper/util.js
src/platforms/mp-alipay/runtime/wrapper/util.js
+6
-3
src/platforms/mp-toutiao/runtime/wrapper/util.js
src/platforms/mp-toutiao/runtime/wrapper/util.js
+4
-3
src/platforms/mp-weixin/runtime/index.js
src/platforms/mp-weixin/runtime/index.js
+5
-7
src/platforms/mp-weixin/runtime/wrapper/util.js
src/platforms/mp-weixin/runtime/wrapper/util.js
+34
-3
未找到文件。
packages/vue-cli-plugin-uni/packages/mp-vue/dist/mp.runtime.esm.js
浏览文件 @
947050b6
...
...
@@ -991,7 +991,8 @@ function observe (value, asRootData) {
!
isServerRendering
()
&&
(
Array
.
isArray
(
value
)
||
isPlainObject
(
value
))
&&
Object
.
isExtensible
(
value
)
&&
!
value
.
_isVue
!
value
.
_isVue
&&
!
value
.
__v_isMPComponent
)
{
ob
=
new
Observer
(
value
);
}
...
...
@@ -5600,7 +5601,7 @@ function nextTick$1(vm, cb) {
function
clearInstance
(
key
,
value
)
{
// 简易去除 Vue 和小程序组件实例
if
(
value
)
{
if
(
value
.
_isVue
||
(
value
.
$vm
&&
value
.
$vm
.
_isVue
)
)
{
if
(
value
.
_isVue
||
value
.
__v_isMPComponent
)
{
return
{}
}
}
...
...
src/platforms/mp-alipay/runtime/index.js
浏览文件 @
947050b6
import
{
handleProps
}
from
'
./wrapper/util
'
import
{
handleProps
,
markMPComponent
}
from
'
./wrapper/util
'
const
MPComponent
=
Component
function
initHook
(
name
,
options
)
{
const
oldHook
=
options
[
name
]
options
[
name
]
=
function
(...
args
)
{
markMPComponent
(
this
)
const
props
=
this
.
props
if
(
props
&&
props
[
'
data-com-type
'
]
===
'
wx
'
)
{
handleProps
(
this
)
...
...
src/platforms/mp-alipay/runtime/wrapper/util.js
浏览文件 @
947050b6
...
...
@@ -6,11 +6,14 @@ import {
}
from
'
uni-shared
'
import
{
handleLink
as
handleBaseLink
handleLink
as
handleBaseLink
,
toSkip
}
from
'
../../../mp-weixin/runtime/wrapper/util
'
import
deepEqual
from
'
./deep-equal
'
export
{
markMPComponent
}
from
'
../../../mp-weixin/runtime/wrapper/util
'
const
customizeRE
=
/:/g
const
customize
=
cached
((
str
)
=>
{
...
...
@@ -145,9 +148,9 @@ export function handleRef (ref) {
const
refName
=
ref
.
props
[
'
data-ref
'
]
const
refInForName
=
ref
.
props
[
'
data-ref-in-for
'
]
if
(
refName
)
{
this
.
$vm
.
$refs
[
refName
]
=
ref
.
$vm
||
ref
this
.
$vm
.
$refs
[
refName
]
=
ref
.
$vm
||
toSkip
(
ref
)
}
else
if
(
refInForName
)
{
(
this
.
$vm
.
$refs
[
refInForName
]
||
(
this
.
$vm
.
$refs
[
refInForName
]
=
[])).
push
(
ref
.
$vm
||
ref
)
(
this
.
$vm
.
$refs
[
refInForName
]
||
(
this
.
$vm
.
$refs
[
refInForName
]
=
[])).
push
(
ref
.
$vm
||
toSkip
(
ref
)
)
}
}
...
...
src/platforms/mp-toutiao/runtime/wrapper/util.js
浏览文件 @
947050b6
import
{
findVmByVueId
,
initRefs
as
initRefsBase
initRefs
as
initRefsBase
,
toSkip
}
from
'
../../../mp-weixin/runtime/wrapper/util
'
export
const
mocks
=
[
'
__route__
'
,
'
__webviewId__
'
,
'
__nodeid__
'
,
'
__nodeId__
'
]
...
...
@@ -19,7 +20,7 @@ export function initRefs (vm) {
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
,
(
components
)
=>
{
components
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
vm
.
$refs
[
ref
]
=
component
.
$vm
||
component
vm
.
$refs
[
ref
]
=
component
.
$vm
||
toSkip
(
component
)
})
})
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
,
(
forComponents
)
=>
{
...
...
@@ -28,7 +29,7 @@ export function initRefs (vm) {
if
(
!
vm
.
$refs
[
ref
])
{
vm
.
$refs
[
ref
]
=
[]
}
vm
.
$refs
[
ref
].
push
(
component
.
$vm
||
component
)
vm
.
$refs
[
ref
].
push
(
component
.
$vm
||
toSkip
(
component
)
)
})
})
}
...
...
src/platforms/mp-weixin/runtime/index.js
浏览文件 @
947050b6
...
...
@@ -2,6 +2,7 @@ import {
cached
,
camelize
}
from
'
uni-shared
'
import
{
markMPComponent
}
from
'
./wrapper/util
'
const
MPPage
=
Page
const
MPComponent
=
Component
...
...
@@ -41,13 +42,10 @@ function initHook (name, options, isComponent) {
isComponent
&&
options
.
lifetimes
&&
options
.
lifetimes
[
name
]
&&
(
options
=
options
.
lifetimes
)
}
const
oldHook
=
options
[
name
]
if
(
!
oldHook
)
{
options
[
name
]
=
function
()
{
initTriggerEvent
(
this
)
}
}
else
{
options
[
name
]
=
function
(...
args
)
{
initTriggerEvent
(
this
)
options
[
name
]
=
function
(...
args
)
{
markMPComponent
(
this
)
initTriggerEvent
(
this
)
if
(
oldHook
)
{
return
oldHook
.
apply
(
this
,
args
)
}
}
...
...
src/platforms/mp-weixin/runtime/wrapper/util.js
浏览文件 @
947050b6
import
{
isObject
}
from
'
uni-shared
'
export
const
mocks
=
[
'
__route__
'
,
'
__wxExparserNodeId__
'
,
'
__wxWebviewId__
'
]
export
function
findVmByVueId
(
vm
,
vuePid
)
{
...
...
@@ -35,7 +39,7 @@ function selectAllComponents (mpInstance, selector, $refs) {
const
components
=
mpInstance
.
selectAllComponents
(
selector
)
||
[]
components
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
$refs
[
ref
]
=
component
.
$vm
||
component
$refs
[
ref
]
=
component
.
$vm
||
toSkip
(
component
)
if
(
__PLATFORM__
===
'
mp-weixin
'
)
{
if
(
component
.
dataset
.
vueGeneric
===
'
scoped
'
)
{
component
.
selectAllComponents
(
'
.scoped-ref
'
).
forEach
(
scopedComponent
=>
{
...
...
@@ -78,7 +82,7 @@ export function initRefs (vm) {
if
(
!
$refs
[
ref
])
{
$refs
[
ref
]
=
[]
}
$refs
[
ref
].
push
(
component
.
$vm
||
component
)
$refs
[
ref
].
push
(
component
.
$vm
||
toSkip
(
component
)
)
})
return
syncRefs
(
refs
,
$refs
)
}
...
...
@@ -102,4 +106,31 @@ export function handleLink (event) {
}
vueOptions
.
parent
=
parentVm
}
}
export
function
markMPComponent
(
component
)
{
// 在 Vue 中标记为小程序组件
const
IS_MP
=
'
__v_isMPComponent
'
Object
.
defineProperty
(
component
,
IS_MP
,
{
configurable
:
true
,
enumerable
:
false
,
value
:
true
})
return
component
}
export
function
toSkip
(
obj
)
{
const
OB
=
'
__ob__
'
const
SKIP
=
'
__v_skip
'
if
(
isObject
(
obj
)
&&
Object
.
isExtensible
(
obj
))
{
// 避免被 @vue/composition-api 观测
Object
.
defineProperty
(
obj
,
OB
,
{
configurable
:
true
,
enumerable
:
false
,
value
:
{
[
SKIP
]:
true
}
})
}
return
obj
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录