Skip to content

define temporary variables in Vue.js template #1172

@mariusa

Description

@mariusa

What problem does this feature solve?

Sometimes we need to compute and reference the same value multiple times in a template.
It would help with readability & performance to be able to define variables in templates.

Somebody asked this here too:
https://stackoverflow.com/questions/43999618/how-to-define-a-temporary-variable-in-vue-js-template

What does the proposed API look like?

There's a suggestion in the answers, but this allows setting only 1 variable:

<li v-for="id in users" :key="id" :set="user = getUser(id)">

maybe like this?

<li v-for="id in users" :key="id" :set="user = getUser(id); var2 = true; var3=getUserPrefs(id)">

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions