vuejs / composition-api

Composition API plugin for Vue 2
https://composition-api.vuejs.org/
MIT License
4.19k stars 343 forks source link

watchEffect is not same as vue3 watchEffect? #633

Closed gitHber closed 3 years ago

gitHber commented 3 years ago
setup() {
    const num = ref(0);
    watchEffect(() => {
      console.log("num change will not trigger this effect");
      num.value = 1;
    });
    setTimeout(() => {
      num.value++;
    }, 5000);
    return {
      num
    };
  }

in vue3, it's right, watchEffect only triggered by value getter(not setter), in composition-api, it will triggered by value setter which means it's not right

vue3-demo https://stackblitz.com/edit/vue-qfisdz sorry, I did't create a demo for @vue/composition-api.

prigaux commented 3 years ago

NB : this bug breaks the asyncComputed function suggested in https://github.com/foxbenjaminfox/vue-async-computed/issues/104 .

(i'm trying to transition from vue2->vue3 by gradually migrating from "options API" to "composition API" with vue2)

gitHber commented 3 years ago

NB : this bug breaks the asyncComputed function suggested in foxbenjaminfox/vue-async-computed#104 .

(i'm trying to transition from vue2->vue3 by gradually migrating from "options API" to "composition API" with vue2)

just for additional, watch api only triggered when watcher value change, but watchEffect api would triggered when watcher value set

ygj6 commented 3 years ago

Solved by https://github.com/vuejs/composition-api/pull/786.