-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template-local variables support #12144
Comments
Here is a similar question asked on StackOverflow: https://stackoverflow.com/questions/54446108/how-to-define-variable-in-vue-template |
As tou replied in other issues this idea has already been dropped before. You can find the pr and issues with v-scope and v-local |
in this scenario, the best thing to do is to create a child component, <td v-for="day in DAYS" :key="day.key">
<my-component :time="makeTime(day, hour)"/>
</td> my-component : <template>
<input
:id="`classTime_${time}`"
v-model="filters.classTimes"
:value="time"
type="checkbox"
>
<label :for="`classTime_${time}`">
{{ time }}
</label>
</template> |
My apologies. I do read that issue and I follow your comment to search for By searching with #2575 [feature request] local variables in v-for |
What problem does this feature solve?
Sometimes when I'm using
v-for
, I feel the need to have a local variable to store the intermediate result from a function call to avoid duplication and unnecessary calls. Others may find the need to give an alias to a property deep in an object.Begin with the code:
The
makeTime()
function was written and called with the same arguments 4x times in each iteration.In order to simplify this code, I use a workaround that uses
v-for
with a single-value array:It would be nice to have a dedicated directive to add the local variables.
What does the proposed API look like?
I'd like to add a dedicated directive for using local variables like this:
The text was updated successfully, but these errors were encountered: