随机背景颜色
<div class="card" :style="{backgroundColor:'rgb('+Math.floor(Math.random() * 129)+','+Math.floor(Math.random() * 129)+','+Math.floor(Math.random() * 129)+',0.6)'}" >
</div>
随机渐变背景颜色
<div class="card" :style="gradientStyle" ></div>
export default {
computed: {
gradientStyle() {
// 随机生成两个深色
const darkColor1 = `rgb(${Math.floor(Math.random() * 160) + 64},${Math.floor(Math.random() * 160) + 64},${Math.floor(Math.random() * 160) + 64})`;
const darkColor2 = `rgb(${Math.floor(Math.random() * 160) + 64},${Math.floor(Math.random() * 160) + 64},${Math.floor(Math.random() * 160) + 64})`;
// 创建一个线性渐变样式字符串
// to right 表示渐变从左到右
return {
background: `linear-gradient(to right, ${darkColor1}, ${darkColor2})`
};
}
},
}