【问题标题】:vue.js push gives TypeError: Cannot read property 'name' of undefinedvue.js push 给出 TypeError: Cannot read property 'name' of undefined
【发布时间】:2018-05-26 08:06:07
【问题描述】:

我有一个类似的东西:

new Vue({    
    el: '#core',
    data: {
        checkedThemes: []
        ...
    }
})

之后:

mounted() {
    ...
    var theme = parseInt(parameters['theme']);
    this.checkedThemes.push(theme);
    ...
}

调用推送会引发 TypeError: Cannot read property 'name' of undefined 但是当我从网页执行此操作(添加一些值)时,它可以工作。

编辑:此错误出现在 Chrome 中。在 Firefox 中,我得到:[Vue 警告]:渲染错误:“TypeError:主题 [checkedTheme] 未定义”

此外,推送后数组被很好地填充。

这个错误是从哪里来的?

【问题讨论】:

  • 清楚地检查您的日志,它会指向您的来源
  • 推送调用,然后它进入一些 vue.js 内部代码
  • 好吧,您至少需要分享日志的屏幕截图,因为我在您的代码中看不到 name
  • 首先,我在你的data() 中没有看到checkedThemes,接下来,parameters 是从哪里来的?
  • 另外,您在 Chrome 中的错误非常具体:themes[checkedTheme] is undefined

标签: javascript vue.js


【解决方案1】:

使用 Firefox 调试是一个更好的主意,因为它说: [Vue警告]:渲染错误:“TypeError:主题[checkedTheme]未定义”

而且错误出现在 html(渲染)部分。

【讨论】:

    猜你喜欢
    • 2017-08-19
    • 1970-01-01
    • 1970-01-01
    • 2021-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 2023-03-15
    相关资源
    最近更新 更多