- Notifications
You must be signed in to change notification settings - Fork 540
Closed
Description
Sometimes you will encounter such a situation:
<template> <div class="container"> <p class="row">{{item && item.a && item.a.b && item.a.b.hello}}</p> <p class="row">{{item && item.a && item.a.b && item.a.b.world}}</p> <p class="row">{{item && item.a && item.a.b && item.a.b.goodbye}}</p> </div> </template>
These code with the same logic need to be written many times.
I hope there is a way to define local variables in the template, then the above code can be abbreviated as:
<template> <div class="container"> <var name="b" :value="item && item.a && item.a.b"></var> <p class="row">{{b && b.hello}}</p> <p class="row">{{b && b.world}}</p> <p class="row">{{b && b.goodbye}}</p> </div> </template>
or
<template> <div class="container" v-var:b="item && item.a && item.a.b"> <p class="row">{{b && b.hello}}</p> <p class="row">{{b && b.world}}</p> <p class="row">{{b && b.goodbye}}</p> </div> </template>
Q: Why not computed?
A: The item
in the above code may come from v-for
, so computed
is not a feasible solution.
chriscalo, doncatnip, mmghv, mariusa, cosimochellini and 18 morecawa-93, skyrpex, woothu, sionzee and optsing
Metadata
Metadata
Assignees
Labels
No labels