V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
linzhe141
V2EX  ›  Vue.js

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

  •  
  •   linzhe141 · 5 天前 · 1166 次点击

    image

    5 条回复    2024-06-26 19:16:29 +08:00
    bojackhorseman
        1
    bojackhorseman  
       5 天前
    怎么定位到 vue 3 源码去了?
    xiyan00
        2
    xiyan00  
       5 天前
    下面是 log 吗
    linzhe141
        3
    linzhe141  
    OP
       5 天前
    @xiyan00 下面是 debug 的 watch 功能输出各项的值
    iidear2015
        4
    iidear2015  
       5 天前   ❤️ 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
    ```
    DOLLOR
        5
    DOLLOR  
       5 天前
    你的 getter 带有副作用,破坏了语义(可能是处于什么 hack 的需求)。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1738 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:35 · PVG 00:35 · LAX 09:35 · JFK 12:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.