亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 vue for 循環中從對象渲染

在 vue for 循環中從對象渲染

Cats萌萌 2021-06-01 18:02:13
我想呈現問題和答案,并將一種樣式附加到問題中,將另一種樣式附加到答案中。我的數據看起來像這樣 dialogTut:{        mainTab:{          q:"data with 42 people?",          a:"hehe",          q:"Are awesome people?",          a:"sometimes",          q:"Are awesome people2?",        }      },我想在 Label 中渲染它,因為它的 nativescript (也許還有其他方法)<StackLayout class="dialog">        <Label v-bind:key="item.index"              :text="item"               :class="[item==q ? 'h3' : '' , 'a']"               v-for="item in mainTab">        </Label>        <Button class="drawer-close-button" text="Cancel" @tap="closeDialog"></Button>    </StackLayout>我嘗試了一些可能性:class 但不起作用。如何呈現整個列表并將 'h3' 類附加到 item.q 并將 'answer' 類附加到 item.a ?
查看完整描述

3 回答

?
大話西游666

TA貢獻1817條經驗 獲得超14個贊

我會以這種方式重組您的數據:


mainTab:[

   {q:"data with 42 people?", a:"hehe"},

   {q:"Are awesome people?", a:"sometimes"}

]

和你的 html:


<template 

   :value="item.q" 

   v-for="(item,index) in mainTab">

   <p class="questionClass" :key="'q_'+index">{{item.q}}</p>

   <p class="answerClass" :key="'a_'+index">{{item.a}}</p>

</template>


查看完整回答
反對 回復 2021-06-03
?
胡說叔叔

TA貢獻1804條經驗 獲得超8個贊

替換為 :class="[item==q ? 'h3' : 'answer']" 或 :class="{ 'h3': item==q, 'answer': item==a }"


查看完整回答
反對 回復 2021-06-03
  • 3 回答
  • 0 關注
  • 266 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號