在 vue 中如何每两个 div 设置一个父 div? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
icemanpro

在 vue 中如何每两个 div 设置一个父 div?

  •  
  •   icemanpro May 15, 2018 3160 views
    This topic created in 2917 days ago, the information mentioned may be changed or developed.

    想生成如下 html

    <div> <div>a</div> <div>b</div> </div> <div> <div>c</div> <div>d</div> </div> <div> <div>e</div> </div> 

    以下代码应该如何修改?

    <template v-for="(l,index) of lists"> <div>l.name</div> </template> 
    5 replies    2018-05-15 19:14:22 +08:00
    ss098
        1
    ss098  
       May 15, 2018   1
    1. 先将 lists 以两个为一组分组(例如 underscore 提供的 chunk 方法)
    2. 通过 v-for 遍历输出

    例子: https://jsfiddle.net/00pkbtww/
    niubee1
        2
    niubee1  
       May 15, 2018
    <template v-for="(l,index) of lists">
    <template v-if="l % 2 === 0">
    <div>
    </template>
    <div>l.name</div>
    <template v-if="l % 2 === 1">
    </div>
    </template>
    </template>
    rabbbit
        3
    rabbbit  
       May 15, 2018
    rabbbit
        4
    rabbbit  
       May 15, 2018
    唔,我好像理解错了
    rabbbit
        5
    rabbbit  
       May 15, 2018
    一楼方法应该是最好的,我这么写估计会被人打死
    About     Help     Advertise     Blog     API     FAQ     Solana     3879 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 33ms UTC 04:47 PVG 12:47 LAX 21:47 JFK 00:47
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86