[英]jQuery changing elements depending on how many times the button has been clicked
[英]Displaying how many times a button has been clicked
我在 HTML 中创建了一个按钮,我想知道如何使用 Vue.js 在控制台中显示它被按下的次数。
这是我到目前为止所做的:
<div class="123">
<button id = "Abutton" @click="abutton()">
<img src="randomimage.png"
style="width: 30px; height: 30px;"
/>
</button>
</div>
在 Vue.js 中:
abutton: function (e) {
const ButtonVal = e.target.value;
console.log("Number of likes:" + ButtonVal)
},
button
没有任何value
......但你可以使用这样的数据属性:
<div class="123">
<button id = "Abutton" @click="abutton()" data-clickcount="0">
<img src="randomimage.png"
style="width: 30px; height: 30px;"
/>
</button>
</div>
在 Vue.js 中:
abutton: function (e) {
// Get the count
const ButtonVal = +(e.target.dataset.clickcount);
// Increment and store it
e.target.dataset.clickcount = ButtonVal++;
// log it
console.log("Number of likes:" + ButtonVal)
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.