如何处理Vue中的错误

时间:2018-10-19 15:41:56

标签: vue.js vuejs2

我有一个很好的问题,就是我很难找到答案。有时我会收到类似这样的错误:

[Vue warn]: Error in render: "TypeError: Cannot read property 'email'undefined"
    found in

    ---> <IUserSettings> at src\IUser\IUserSettings.vue
           <Imenu> at src\Imenu.vue
             <Icontent> at src\Icontent.vue
               <ISlider> at src\UI\slider\ISlider.vue
                 <ISetup> at src\ISetup.vue
                   <ISlider> at src\UI\slider\ISlider.vue
                     <Iaccess> at src\Iaccess.vue
                       <ISlider> at src\UI\slider\ISlider.vue
                         <App> at src\App.vue
                           <Root>
  TypeError: Cannot read property 'email' of undefined
        at Proxy.render (eval at ./node_modules/vue-loader/lib/template-compiler/index.js?{"id":"data-v-2e2bc539","hasScoped":true,"transformToRequire":{"video":["src","poster"],"source":"src","img":"src","image":"xlink:href"},"buble":{"transforms":{}}}!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./src/IUser/IUserSettings.vue (app.js:6008), <anonymous>:159:63)
        at VueComponent.Vue._render (vue.esm.js?efeb:4544)
        at VueComponent.updateComponent (vue.esm.js?efeb:2788)
        at Watcher.get (vue.esm.js?efeb:3142)
        at Watcher.run (vue.esm.js?efeb:3219)
        at flushSchedulerQueue (vue.esm.js?efeb:2981)
        at Array.eval (vue.esm.js?efeb:1837)
        at flushCallbacks (vue.esm.js?efeb:1758)

我如何找到错误的来源?是否可以跟踪发生错误的标记?谢谢

1 个答案:

答案 0 :(得分:1)

该错误发生在跟踪中看到的第一个元素上。在您的示例中,它发生在src\IUser\IUserSettings.vue内部。在该元素中查找具有email属性的对象,并确保它不是undefined