Subscribe on changes!

template local variable pollution

avatar
Feb 10th 2023

Vue version

3.2.47

Link to minimal reproduction

https://github.com/kinfuy/vue-template-bug

Steps to reproduce

<template>
  <div v-show="false">
     {{ text = ['1,2,3,4,5'] }}
  </div>
  <div>{{ text }}</div>

</template>

image

What is expected?

text not found

What is actually happening?

text normal operation

System Info

No response

Any additional comments?

No response

avatar
Feb 10th 2023

I think this isn't a bug. Vue3 is the same presentation form as Vue2.

https://stackblitz.com/edit/vue2-vue-cli-d2v8f6?file=src/App.vue

avatar
Feb 10th 2023

I think this isn't a bug too. {{ text = ['1,2,3,4,5'] }} is compiled by the compiler into code text.value = ['1,2,3,4,5'], and rendered run when. And v-show just controls the display property. text.value = ['1,2,3,4,5'] will still execute, which I think is expected

avatar
Feb 10th 2023

I think this kind of feeling is a little dark magic. Declare variables in the template, and they are valid in the entire template. This vue2 has the same effect. I'm not sure if it needs to be modified @AlexVagrant @baiwusanyu-c

avatar
Feb 10th 2023

You are modifying data while rendering the component so this is expected behavior. Currently you are not supposed to declare variable inside templates.