提交 97e8900d 编写于 作者: fxy060608's avatar fxy060608

fix(h5): Vue.js devtools (#3492)

上级 13c8eddb
...@@ -3927,13 +3927,13 @@ function resetHookState(hooks) { ...@@ -3927,13 +3927,13 @@ function resetHookState(hooks) {
function injectHook(type, hook, target = currentInstance, prepend = false) { function injectHook(type, hook, target = currentInstance, prepend = false) {
if (target) { if (target) {
// fixed by xxxxxx // fixed by xxxxxx
if (uniShared.isRootHook(type)) { if (uniShared.isRootHook(type) && target.$pageInstance) {
// 系统保留组件,如 view,app 等 // 系统保留组件,如 view,app 等
if (target.type.__reserved) { if (target.type.__reserved) {
return; return;
} }
if (target !== target.root) { if (target !== target.$pageInstance) {
target = target.root; target = target.$pageInstance;
if (uniShared.isRootImmediateHook(type)) { if (uniShared.isRootImmediateHook(type)) {
// 作用域应该是组件还是页面?目前绑定的是页面 // 作用域应该是组件还是页面?目前绑定的是页面
const proxy = target.proxy; const proxy = target.proxy;
...@@ -8252,6 +8252,7 @@ function createComponentInstance(vnode, parent, suspense) { ...@@ -8252,6 +8252,7 @@ function createComponentInstance(vnode, parent, suspense) {
} }
instance.root = parent ? parent.root : instance; instance.root = parent ? parent.root : instance;
instance.emit = emit$1.bind(null, instance); instance.emit = emit$1.bind(null, instance);
instance.$pageInstance = parent && parent.$pageInstance;
// apply custom element special handling // apply custom element special handling
if (vnode.ce) { if (vnode.ce) {
vnode.ce(instance); vnode.ce(instance);
......
...@@ -3954,13 +3954,13 @@ function resetHookState(hooks) { ...@@ -3954,13 +3954,13 @@ function resetHookState(hooks) {
function injectHook(type, hook, target = currentInstance, prepend = false) { function injectHook(type, hook, target = currentInstance, prepend = false) {
if (target) { if (target) {
// fixed by xxxxxx // fixed by xxxxxx
if (isRootHook(type)) { if (isRootHook(type) && target.$pageInstance) {
// 系统保留组件,如 view,app 等 // 系统保留组件,如 view,app 等
if (target.type.__reserved) { if (target.type.__reserved) {
return; return;
} }
if (target !== target.root) { if (target !== target.$pageInstance) {
target = target.root; target = target.$pageInstance;
if (isRootImmediateHook(type)) { if (isRootImmediateHook(type)) {
// 作用域应该是组件还是页面?目前绑定的是页面 // 作用域应该是组件还是页面?目前绑定的是页面
const proxy = target.proxy; const proxy = target.proxy;
...@@ -8349,6 +8349,7 @@ function createComponentInstance(vnode, parent, suspense) { ...@@ -8349,6 +8349,7 @@ function createComponentInstance(vnode, parent, suspense) {
} }
instance.root = parent ? parent.root : instance; instance.root = parent ? parent.root : instance;
instance.emit = emit$1.bind(null, instance); instance.emit = emit$1.bind(null, instance);
instance.$pageInstance = parent && parent.$pageInstance;
// apply custom element special handling // apply custom element special handling
if (vnode.ce) { if (vnode.ce) {
vnode.ce(instance); vnode.ce(instance);
......
...@@ -85,7 +85,10 @@ export function setupPage(comp: any) { ...@@ -85,7 +85,10 @@ export function setupPage(comp: any) {
clone: true, // 页面组件可能会被其他地方手动引用,比如 windows 等,需要 clone 一份新的作为页面组件 clone: true, // 页面组件可能会被其他地方手动引用,比如 windows 等,需要 clone 一份新的作为页面组件
init: initPage, init: initPage,
setup(instance) { setup(instance) {
instance.root = instance // 组件 root 指向页面 // instance.root = instance // 组件 root 指向页面
// 修改 root 会影响 vue devtools
instance.$pageInstance = instance // 组件 $pageInstance 指向页面
// 组件的 $pageInstance 赋值,是在 vue 内核 createComponentInstance 中 root 赋值的地方实现
const route = usePageRoute() const route = usePageRoute()
// 存储参数,让 initHooks 中执行 onLoad 时,可以访问到 // 存储参数,让 initHooks 中执行 onLoad 时,可以访问到
const query = decodedQuery(route.query) const query = decodedQuery(route.query)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册