提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
刚接触前端开发的菜鸟一枚,记录下开发中自己觉得需要记下的功能开发思路
需求:点击按钮,将按钮的值传入 input 内,按钮样式发生变化(已点击);再次点击按钮,将按钮的值从 input 内清除,按钮样式恢复(未点击)
大致代码(只写了部分,记录思路)(单个按钮):
<!-- HTML部分 -->
<!-- 按钮 -->
<a-button class="commentLabelBtn" type="primary" :class="{active: isActive1}" @click="commentLabel1($event)">
{
{
value }}
</a-button>
<a-input v-model="form.comment">
{
{
form.comment }}
</a-input>
<!-- script部分(ts) -->
isActive1 = false;
commentLabel1(event) {
if (this.isActive1 == false) {
this.isActive1 = true;
this.form.comment += event.srcElement.innerText + ';';
} else {
let test = this.form.comment.replace('value', ''); // 需要直接写 value 的值,不能写变量名
this.form.comment = test;
this.isActive1 = false;
}
}
<!-- CSS部分 -->
.commentLabelBtn {
width: auto;
height: 28px;
margin: 8px 8px 8px 0;
background: #eaeff5;
color: #000000 !important;
border-radius: 50px;
border: none;
}
.active {
background-color: #435bf7;
color: #fff !important;
}
实现效果(多个按钮)
有问题的地方可以一起讨论下哈