V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
ooo4
V2EX  ›  Vue.js

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

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

    image

    5 replies    2024-06-26 19:16:29 +08:00
    dumbass
        1
    dumbass  
       Jun 26, 2024
    怎么定位到 vue 3 源码去了?
    xiyan00
        2
    xiyan00  
       Jun 26, 2024
    下面是 log 吗
    ooo4
        3
    ooo4  
    OP
       Jun 26, 2024
    @xiyan00 下面是 debug 的 watch 功能输出各项的值
    iidear2015
        4
    iidear2015  
       Jun 26, 2024   ❤️ 1
    ```
    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
        5
    AV1  
       Jun 26, 2024
    你的 getter 带有副作用,破坏了语义(可能是处于什么 hack 的需求)。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2369 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 04:23 · PVG 12:23 · LAX 21:23 · JFK 00:23
    ♥ Do have faith in what you're doing.