How to define local variables in Vue3's template files

There are situations when you'd like to use local variables in the likes of [Java's Thymeleaf](, for example. 

<li v-if="setting" :key="" :with="chart = fromSetting(setting)">
  {{ }}

P.S. This solution only works with template rendering to display data. Passing it to events won't work since it will always pass the latest evaluated value from the loop.

Nick Ciolpan
19 Sep 2021
« Back to post