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

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

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(\'能提交\');
        }
      }
   }
}

以上这篇vue 实现特定条件下绑定事件就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容