vue在:class语法中,如何动态拼接变量

https://img3.mukewang.com/5c80ccfa0001fe9e08000192.jpg

如图,想在一个v-for循环中,动态拼接(item.realCode + 'LastWeek')使其成为一个变量来 动态求值

幕布斯7119047
浏览 7915回答 2
2回答

慕的地6264312

我懂了……你试试这个<div>{{list[item.realCode+'LastWeek']}}</div>模拟一个data:data(){&nbsp; &nbsp; return {&nbsp; &nbsp; &nbsp; &nbsp; item: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;realCode: 'word'&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; list: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wordLastWeek: '2017-09',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wordLastYear: '2016'&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}

红糖糍粑

动态class是支持三目表达式的。:class="userinfo.memberLevel == 0 ? 'agreement_content' : 'agreement_content-o'".:class="(item.realCode + 'LastWeek')<0 ? negative : positive"
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript