Vue: this is undiefind ... 搞笑的东西

Created on 14 Nov 2018  ·  9Comments  ·  Source: vuejs/vue

image

image
image

大哥 你们是不是换了 router 的写个啊! 文档没更新啊 搞死人啊??

Most helpful comment

文档写得非常清楚:

不要在选项属性或回调上使用箭头函数,比如 created: () => console.log(this.a)vm.$watch('a', newValue => this.myMethod())。因为箭头函数是和父级上下文绑定在一起的,this 不会是如你所预期的 Vue 实例,经常导致 Uncaught TypeError: Cannot read property of undefinedUncaught TypeError: this.myMethod is not a function 之类的错误。

https://cn.vuejs.org/v2/guide/instance.html#%E5%AE%9E%E4%BE%8B%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E9%92%A9%E5%AD%90

很显然你没有吸取上次的教训。

All 9 comments

Hello, your issue has been closed because it does not conform to our issue requirements. In order to ensure every issue provides the necessary information for us to investigate, we require the use of the Issue Helper when creating new issues. Thank you!


你好,你的 issue 不符合我们所要求的格式,因此已被自动关闭。为了确保每个 issue 都提供必需的相关信息,请务必使用我们的 Issue 向导 来创建新 issue,谢谢!

文档写得非常清楚:

不要在选项属性或回调上使用箭头函数,比如 created: () => console.log(this.a)vm.$watch('a', newValue => this.myMethod())。因为箭头函数是和父级上下文绑定在一起的,this 不会是如你所预期的 Vue 实例,经常导致 Uncaught TypeError: Cannot read property of undefinedUncaught TypeError: this.myMethod is not a function 之类的错误。

https://cn.vuejs.org/v2/guide/instance.html#%E5%AE%9E%E4%BE%8B%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E9%92%A9%E5%AD%90

很显然你没有吸取上次的教训。

笑出声

文档写得非常清楚:

不要在选项属性或回调上使用箭头函数,比如 created: () => console.log(this.a)vm.$watch('a', newValue => this.myMethod())。因为箭头函数是和父级上下文绑定在一起的,this 不会是如你所预期的 Vue 实例,经常导致 Uncaught TypeError: Cannot read property of undefinedUncaught TypeError: this.myMethod is not a function 之类的错误。

https://cn.vuejs.org/v2/guide/instance.html#%E5%AE%9E%E4%BE%8B%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E9%92%A9%E5%AD%90

很显然你没有吸取上次的教训。

React 用户 转过来 我都写 () => 写习惯了

文档写得非常清楚:

不要在选项属性或回调上使用箭头函数,比如 created: () => console.log(this.a)vm.$watch('a', newValue => this.myMethod())。因为箭头函数是和父级上下文绑定在一起的,this 不会是如你所预期的 Vue 实例,经常导致 Uncaught TypeError: Cannot read property of undefinedUncaught TypeError: this.myMethod is not a function 之类的错误。

https://cn.vuejs.org/v2/guide/instance.html#%E5%AE%9E%E4%BE%8B%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E9%92%A9%E5%AD%90

很显然你没有吸取上次的教训。

image
hai'yo还有如果不支持 为什么 Layout 里面data => 的东西 都可以出来??

铁憨憨一个

@rainbowMorelhahahah 你可以在 data 里面也用一下 this ,你就发现也出不来了。。。建议可以先看看 文档 学学什么是箭头函数,再来想这个问题

这种问题 明显是自己 操作的问题啊,好好看看文档吧先。

已 block,走好不送。

Was this page helpful?
0 / 5 - 0 ratings

Related issues

finico picture finico  ·  3Comments

loki0609 picture loki0609  ·  3Comments

seemsindie picture seemsindie  ·  3Comments

lmnsg picture lmnsg  ·  3Comments

robertleeplummerjr picture robertleeplummerjr  ·  3Comments