Skip to content

watch and watchEffect #12684

Jan 11, 2025 · 3 comments · 2 replies
Discussion options

You must be logged in to vote

JavaScript (like many languages) uses short-circuit evaluation for operands of logical operators.

So when you write this:

if (temp.value >= 60 || height.value >= 80) {

If the left-hand operand (temp.value >= 60) is truthy, it won't evaluate the right-hand operand (height.value >= 80). As a result, height.value won't be tracked as a dependency of watchEffect and changes to height.value won't have any impact.


It isn't clear to me what behaviour you want, but I assume you only want to 'send a request' when the condition transitions from false to true.

There are several ways you could achieve that. For example, you could use a computed:

const isEnough = computed(() => temp.value >= 60 || height

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@Eriana-Fang
Comment options

@skirtles-code
Comment options

Answer selected by edison1105
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants