最近需求需要用户自己选择颜色配置,,我以为会很难就百度有什么插件能实现,,然后就使用input标签就能达到,,上代码
这是js原生写法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="color" class="color">
<script>
var color=document.querySelector('.color')
// console.log(color.value);
color.addEventListener('change',function(){
console.log(color.value);
})
</script>
</body>
</html>
vue的话更简单,使用v-mode绑定就可以了,,我一开始还想着用ref拿到,ref也是可以的但v-model更舒服
<input type="color" v-model="motif" ref="color">
但不建议移动端使用,,太丑了