ooo4
V2EX  ›  Vue.js

这个 x 为什么是 true?看不懂了

  •  
  •   ooo4 · Jun 26, 2024 · 3416 views
    This topic created in 867 days ago, the information mentioned may be changed or developed.

    image

    5 replies  •  2024-06-26 19:16:29 +08:00
    dumbass
    dumbass
    Jun 26, 2024
    1
    怎么定位到 vue 3 源码去了?
    xiyan00
    xiyan00
    Jun 26, 2024
    2
    下面是 log 吗
    ooo4
    ooo4
    OP
    Jun 26, 2024
    3
    @xiyan00 下面是 debug 的 watch 功能输出各项的值
    iidear2015
    iidear2015
    Jun 26, 2024❤️1
    4
    ```
    self.effect = {
    _dirty: true,
    get dirty() {
    const v = this._dirty;
    this._dirty = false;
    return v;
    },
    set dirty(v) {
    this._dirty = v;
    }
    }

    if (self.effect.dirty) {
    console.log(self.effect.dirty)
    }

    // false
    ```
    AV1
    AV1
    Jun 26, 2024
    5
    你的 getter 带有副作用,破坏了语义(可能是处于什么 hack 的需求)。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2062 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:01 · PVG 23:01 · LAX 07:01 · JFK 10:01
    ♥ Do have faith in what you're doing.