随机颜色
<button @click="btn">点击</button><div :style="{color:colorRender}" >内容</div>
data(){return{listColor:['red','blue','yellow','pink','green'],colorRender:""}},//取整 Math.floor 的随机数 Math.random()methods:{btn(){var colorIndex =Math.floor(Math.random()*this.listColor.length)console.log(colorIndex); //listColor数组的随机下标console.log( this.listColor[colorIndex]); //找到颜色this.colorRender = this.listColor[colorIndex] } }