Vue.js 中如何获取 input 元素的值
<template>
<div>
<input type='text' v-on:input='handleInput($event)'>
</div>
</template>
<script>
export default {
methods: {
handleInput(event) {
console.log(event.target.value);
}
}
}
</script>
<p>在上面的例子中,<code>v-on:input</code> 指令监听了 <code>input</code> 事件,并调用了 <code>handleInput</code> 方法,使用 <code>$event</code> 传递了事件对象。在 <code>handleInput</code> 方法中,可以通过 <code>event.target</code> 来获取输入框的 DOM 元素,从而获取输入框的值。</p>
原文地址: https://www.cveoy.top/t/topic/mUWy 著作权归作者所有。请勿转载和采集!