16进制转rgba
- 方法
function toRgba(color, opacity) {
return (
"rgba(" +
parseInt(color.substring(1, 3), 16) +
"," +
parseInt(color.substring(3, 5), 16) +
"," +
parseInt(color.substring(5, 7), 16) +
"," +
opacity +
")"
);
}
- 使用
const color = toRgba('#ff0000', .1); // rgba(255,0,0,0.1)
.test {
color: v-bind(color);
}