Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<TypeError: undefined is not an object(evalusting 'vm.$app.hooks')> #2356

Closed
feliciaZH opened this issue Sep 2, 2019 · 6 comments
Closed
Assignees

Comments

@feliciaZH
Copy link

feliciaZH commented Sep 2, 2019

在自定义组件里面用组件,会报错

代码结构

// comment-list组件里面用at-user组件
// comment-list.wpy
<template>
<at-user :filters="['emoji']" :summary="nickname"></at-user>
</template>
<config>
{
"component": true,    //声明组件
"usingComponents": {        //可以使用的组件
  "at-user": "~@/components/at-user"
}

}
</config>


看node_modules\@wepy\core\dist\wepy.js
function callUserHook (vm, hookName, arg) {

  var pageHook = vm.hooks[hookName];
  var appHook = vm.$app.hooks[hookName];

  arg = isFunc(pageHook) ? pageHook.call(vm, arg) : arg;
  arg = isFunc(appHook) ? appHook.call(vm, arg) : arg;



return arg;
}
分析,如果传入的vm是个Component,那么$app是不存在的,还请加个try{}catch(e){}!!!
 ```
@feliciaZH
Copy link
Author

image

@feliciaZH feliciaZH changed the title hooks <TypeError: undefined is not an object(evalusting 'vm.$app.hooks')> Sep 2, 2019
@feliciaZH feliciaZH reopened this Sep 2, 2019
@Gcaufy Gcaufy self-assigned this Sep 10, 2019
@LiuHD
Copy link

LiuHD commented Sep 22, 2019

这个问题怎么样了?有什么临时的解决办法么?现在遇到了同样的问题,小程序一旦触发就会失去响应,挺严重的

@hdsuperman
Copy link

同问 遇到同样的问题,有时候vm 为 WepyComponent 有$app 属性 有时候没有,没有的时候调用hook直接报错,程序崩溃

PS 扫描加群N次 没有回复是什么问题呢?

@hdsuperman
Copy link

找到临时解决方案:
注释掉 node_modules 下 @wepy/core/dist/wepy.js 的钩子:

      // if (vm._init) {
      //   dirty = callUserHook(vm, 'before-setData', dirty);
      // }

同时 app.wpy 不使用 before-setData

@shuaibird
Copy link

找到临时解决方案:
注释掉 node_modules 下 @wepy/core/dist/wepy.js 的钩子:

      // if (vm._init) {
      //   dirty = callUserHook(vm, 'before-setData', dirty);
      // }

同时 app.wpy 不使用 before-setData

手动去操作还是挺麻烦的,这里写了个插件 wepy-remove-before-set-data

@Gcaufy
Copy link
Collaborator

Gcaufy commented Mar 8, 2020

Duplicates: #2486

这个问题之前定位到了,并且在这个版本 @wepy/core@2.0.0-alpha.14
中有处理。

@Gcaufy Gcaufy closed this as completed Mar 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants