1.通过设置button样式来控制点击事件是否启用
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>通过给button设置样式来控制点击事件是否显示</title>
<script src="js/jquery-2.1.0.js"></script>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
<button type="button" class="butt" @click="tanchu">兑换</button>
</div>
<script>
var vm = new Vue({
el: '#app',
data: {
message: 3
},
mounted() {
if(this.message>5){
$('.butt').html('已兑换').addClass('disbutt')
}else{
$('.butt').html('兑换').removeClass('disbutt')
}
},
methods: {
tanchu: function() {
alert('兑换');
}
}
});
</script>
<style type="text/css">
.disbutt {
pointer-events: none;
cursor: not-allowed;
box-shadow: none;
opacity: .65;
background: #e4e4e4;
color: #0b0b0b;
cursor: not-allowed;
}
button {
width: 80px;
height: 40px;
background-color: #1B9DC7;
color: #FFFFFF;
text-align: center;
line-height: 40px;
cursor: pointer;
border: 0;
outline: none;
border-radius: 10px;
}
</style>
</body>
</html>
2.通过在绑定点击事件时多添加一个表示变量,根据变量的值来控制点击事件是否启用
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>通过变量来控制点击事件是否启用</title>
<script src="js/jquery-2.1.0.js"></script>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
<button type="button" @click="buttonShow && lingqu()">领取</button>
</div>
<script>
var vm = new Vue({
el: '#app',
data: {
buttonShow :false
},
methods: {
lingqu: function() {
alert('领取');
}
}
});
</script>
</body>
</html>