我有钩住同样的方法webcamSendRequestButton
使用vue.js
<button v-on:click="webcamSendRequestButton" value="0" type="button" class="webcam-send-request-button" :disabled="disabled">Verify</button>
<button v-on:click="webcamSendRequestButton" value="1" type="button" class="webcam-send-request-button" :disabled="disabled">Verify</button>
<button v-on:click="webcamSendRequestButton" value="2" type="button" class="webcam-send-request-button" :disabled="disabled">Verify</button>
<button v-on:click="webcamSendRequestButton" value="3" type="button" class="webcam-send-request-button" :disabled="disabled">Verify</button>
,我调用Ajax单击该按钮时,页面上的几个按钮。在jQuery或JS中,当点击按钮时,获得按钮的值非常简单。$(this).val();
如何在vue中单击按钮时获取按钮的值?
var app = new Vue({
el: '#my-div',
methods: {
webcamSendRequestButton: function() {
const buttonValue = ??? // How do I fetch the value over here
$.ajax({
url: "someurl",
type: "POST",
data: {
value: buttonValue
},
success: function (data) {
// Omitted for brevity
}
});
}
}
});
它不起作用。我看不到传递给ajax调用中的data方法的'buttonValue'。整个对象在标题'value:buttonValue'中缺失。解决方案是可行的。 – zaq
如果你在处理程序代码的顶部执行'console.log(e.target.value)',你会得到正确的值吗?你有没有试过对'v-on:click'指令使用'native'修饰符使其成为'v-on:click.native'? –
我知道接受的答案是有效的,但如果按钮的值不再作为文字数字静态提供给视图本身,而是变为动态变量的值,则该方法不再有效。你可能会发现这是必需的。 –