I want to get a string input and display it, along with the number of characters of the string.
Need help to implement.
<section id="app"> <h2>Learn Vue Works</h2> <input type="text" @input="saveInput"> <button @click="setText">Set Text</button> <br> <p>{{ qry }} {{ message }}</p>
====app.js====================================== p>
const app = Vue.createApp({ data() { return { message: 'Vue is great!', qry: 'Query String : ', currentSearchInput: '', }; }, methods: { setText() { this.message = this.currentUserInput; }, saveInput(event) { this.currentUserInput = event.target.value; }, }, }); app.mount('#app');
Thanks in advance.
P粉7887656792024-02-22 14:09:16
Use v-model to bind currentSearchInput
to the input. You don't need to saveInput
at all.
{{currentSearchInput}} {{currentSearchInput.length}}
setText() { this.message = this.currentSearchInput; },
Your code has currentSearchInput
and currentUserInput
. typo?