-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
65 lines (59 loc) · 1.61 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<template>
<div id="app">
<h1 :style="{ color: textColor }">欢迎来到我的网站</h1>
<div class="avatar" :style="{ backgroundColor: avatarColor }">
用户头像
</div>
<!-- 颜色选择器 -->
<input type="color" v-model="colorInput" @input="updateColors" />
<!-- 文本输入框 -->
<input
type="text"
v-model="colorInput"
placeholder="输入颜色值(如 #ff0000)"
@input="updateColors"
/>
<button @click="updateColors">更新颜色</button>
</div>
</template>
<script>
export default {
data() {
return {
colorInput: "#ff0000", // 默认颜色
textColor: "#000000", // 主题文字颜色
avatarColor: "#ff0000", // 头像背景颜色
};
},
methods: {
updateColors() {
// 验证输入的颜色值是否有效
const isValidColor = /^#([0-9A-F]{3}|[0-9A-F]{6})$/i.test(
this.colorInput,
);
if (isValidColor) {
this.avatarColor = this.colorInput; // 更新头像背景颜色
this.textColor = this.colorInput; // 更新主题文字颜色
} else {
alert("请输入有效的颜色值,例如 #ff0000");
}
},
},
};
</script>
<style>
#app {
text-align: center;
padding: 50px;
}
.avatar {
width: 100px;
height: 100px;
margin: 20px auto;
display: flex;
align-items: center;
justify-content: center;
color: #ffffff;
border-radius: 50%;
}
</style>