getRandomColor
获取随机16进制颜色
基础用法
ts
import { getRandomColor } from '@lichang666/utils'
getRandomColor() // 随机颜色
demo
点击按钮获取随机颜色方块
#f1843d
vue
<template>
<button @click="getColor">获取颜色</button>
<div :style="{ backgroundColor: color }">{{ color }}</div>
</template>
<script setup lang="ts">
import { getRandomColor } from '@lichang666/utils'
import { ref } from 'vue'
const color = ref(getRandomColor())
const getColor = () => {
color.value = getRandomColor()
}
</script>