1.效果图:
2.html
<view class="add" :style="{'background': dynamicBackgroundColor, 'border-color': 'white'}" @click="handleClick">添加新地址 </view>
3.js
formData: {name: '',phoneNumber: '',addressDetail: ''}//利用computed计算属性为背景颜色赋值
computed: {dynamicBackgroundColor() {return this.formData.name && this.formData.phoneNumber && this.formData.addressDetail ?'rgba(265,165,0,1)' : 'rgba(265,165,0,0.29)';}},handleClick() {if (this.dynamicBackgroundColor === 'rgba(265,165,0,1)') {// 只有当背景颜色的透明度为1时才触发点击事件的逻辑 console.log('触发点击事件');// 执行其他逻辑 }},