vue 实现特定条件下绑定事件

今天写了个小功能,看起来挺简单,写的过程中发现了些坑。 1.div没有disabled的属性,所以得写成button 2.disabled在data时,默认是true,使得初始化时,默认置灰按钮,无法点击 <div cla...

今天写了个小功能,看起来挺简单,写的过程中发现了些坑。

1.div没有disabled的属性,所以得写成button

2.disabled在data时,默认是true,使得初始化时,默认置灰按钮,无法点击

<div class='form-item'>
  <div class="checkWrap clearfix" @click='checkMark()'>
    <div class="checkBox" v-show="checkShow"></div>
  </div>
  <div>我已阅读并接受<a href="http://www.baidu.com" rel="external nofollow" @click="conserve()">《xxx服务协议》</a>及隐私保护条款</div>
</div>
<button class='btn' ref='btn_submit' :disabled="isDisable" @click="check()">
  提交
</button>
export default {
  data() {
    return {
       checkShow: false,
      isDisable: true,
    }
  },

methods: {
  
/**
 * 协议勾选
 */
checkMark() {
  this.checkShow = !this.checkShow;
  if (this.checkShow === true) { 
    this.isDisable = false; //打勾时,可以点击按钮
    this.$refs.btn_submit.style.background = '#fa8919';
  } else {
    this.isDisable = true;  //不打勾时,不可以点击按钮
    this.$refs.btn_submit.style.background = '#999';
  }
},
/**
 *   提交按钮
 */
   check() {
      if (this.checkShow === false) {
          console.log('不能提交');
        } else { 
          console.log('能提交');
        }
      }
   }
}

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
admin
admin

651 篇文章

作家榜 »

  1. admin 651 文章
  2. 粪斗 185 文章
  3. 王凯 92 文章
  4. 廖雪 78 文章
  5. 牟雪峰 12 文章
  6. 李沁雪 9 文章
  7. 全易 2 文章
  8. Stevengring 0 文章