JS代码
//储存随机颜色
data: {
colorArr: ["#EE2C2C", "#ff7070", "#EEC900", "#4876FF", "#ff6100",
"#7DC67D", "#E17572", "#7898AA", "#C35CFF", "#33BCBA", "#C28F5C",
"#FF8533", "#6E6E6E", "#428BCA", "#5cb85c", "#FF674F", "#E9967A",
"#66CDAA", "#00CED1", "#9F79EE", "#CD3333", "#FFC125", "#32CD32",
"#00BFFF", "#68A2D5", "#FF69B4", "#DB7093", "#CD3278", "#607B8B"],
randomColorArr: [],
labLen:'',
good:''
}
判断代码
//判断
var gudong = that.data.gudong
var labLen = gudong.length,
colorArr = that.data.colorArr,
colorLen = colorArr.length,
randomColorArr = [];
//判断执行
for (var i = 0; i <= colorLen;i++) {
let random = colorArr[Math.floor(Math.random() * colorLen)];
console.log(random)
randomColorArr.push(random);
}
that.setData({
randomColorArr: randomColorArr
});
console.log(randomColorArr)
WXML代码
<view data-key="{{key}}" style="background:{{randomColorArr[key]}}">{{item.upshow}}</view>