Joh*_*n P 7 javascript vue.js vuejs2
我正在Vue.js中构建组件。我在页面上有一个输入,用户可以在其中输入一定的信用额度。目前,我正在尝试创建一个将输入金额记录到控制台的函数,当我键入它时。(最终,我将根据用户输入显示/隐藏所请求的文档。我没有希望他们必须单击“提交”按钮。)
当我在输入字段中使用Tab键/单击时,下面的代码将其记录下来。这是我的component.vue:
<template>
<div class="col s12 m4">
<div class="card large">
<div class="card-content">
<span class="card-title">Credit Limit Request</span>
<form action="">
<div class="input-field">
<input v-model="creditLimit" v-on:change="logCreditLimit" id="credit-limit-input" type="text">
<label for="credit-limit-input">Credit Limit Amount</label>
</div>
</form>
<p>1. If requesting $50,000 or more, please attach Current Balance Sheet (less than 1 yr old).</p>
<p>2. If requesting $250,000 or more, also attach Current Income Statement and Latest Income Tax Return.</p>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'licenserow',
data: () => ({
creditLimit: ""
}),
methods: {
logCreditLimit: function (){
console.log(this.creditLimit)
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
如果更改methods为computed,则可以使用-但Invalid handler for event: change每次记录该值时都会出现一条错误消息。
Ber*_*ert 13
使用input事件。
<input v-model="creditLimit" v-on:input="logCreditLimit" id="credit-limit-input" type="text">
Run Code Online (Sandbox Code Playgroud)
change仅在元素失去输入元素的焦点时触发。input每次文本更改时触发。
| 归档时间: |
|
| 查看次数: |
13912 次 |
| 最近记录: |