黑夜的雨

uni-app

导航

如何向数组对象中加如元素(本里是两个对象数组拼接的)

1.模板中

<view class="standard" @tap="showModal" data-target="bottomModal" :style="{background:item.color}" v-for="(item,index) in memberMenuList"
:key="index">
<view class="standard-top">
<image class="img" :src="item.img" mode=""></image>
<view class="introduce">
<view class="f1">{{item.name}}</view>
<view class="f2">有效期:{{item.days}}天·每日登录送{{item.diamondNum}}钻</view>
</view>
</view>
<view class="standard-price">
<view class="price">
<view class="newsprice">¥{{item.presentPrice}}</view>
<view class="oldprice"><s>原价:¥{{item.originalPrice}}</s></view>
</view>
</view>
</view>

2.js中的实现 

<script>
export default {
data() {
return {
user:[],
memberMenuList:[],

standards: [{
color: "linear-gradient(45deg,#f6fbfe,#eff3fc)"
},
{
color: "linear-gradient(45deg,#fef9f5,#f9eddb)"
},
{
color: "linear-gradient(45deg,#fffee9,#fff0b4)"
},
]

methods: {
//充值添加背景色
addElement(){
//创建数组
let array = [];
for (let i = 0; i < this.memberMenuList.length; i++) {
let j = i;
let num = 1;
if(j>2){
j = i-j*num;
if(j==2){
num = num+1;
}
}
array.push(
Object.assign(this.memberMenuList[i],this.standards[j])
)
}
this.memberMenuList = array;
console.log(this.memberMenuList);
}

}

3.memberMenuList是个数组对象从后端拿到

 

posted on 2020-08-12 17:29  黑夜的雨  阅读(1232)  评论(0编辑  收藏  举报