javascript - v-on:change not calling method in nuxt.js - Stack Overflow

This seems like a simple thing to do so I'm not exactly sure what I'm doing wrong here, I fol

This seems like a simple thing to do so I'm not exactly sure what I'm doing wrong here, I followed this question how to fire an event when v-model changes

but I cant seem to get it to work..

This is my ponent

<template>
    <div>
        <input type="text" v-model="searchTerm" v-on:change="search" />
    </div>
</template>

<script>
export default {
   data() {
       return {
           searchTerm: ''
       }
   },
   methods: {
       search() {
           console.log(this.searchTerm);
       }
   }
}
</script>

now basically what I'm trying to do is when a user starts typing in the input, fire this event and console.log() the updated searchTerm, but when I start typing nothing is logged to the console??

Am I doing something wrong? Is this not how you listen to v-model changes in nuxt?

This seems like a simple thing to do so I'm not exactly sure what I'm doing wrong here, I followed this question how to fire an event when v-model changes

but I cant seem to get it to work..

This is my ponent

<template>
    <div>
        <input type="text" v-model="searchTerm" v-on:change="search" />
    </div>
</template>

<script>
export default {
   data() {
       return {
           searchTerm: ''
       }
   },
   methods: {
       search() {
           console.log(this.searchTerm);
       }
   }
}
</script>

now basically what I'm trying to do is when a user starts typing in the input, fire this event and console.log() the updated searchTerm, but when I start typing nothing is logged to the console??

Am I doing something wrong? Is this not how you listen to v-model changes in nuxt?

Share Improve this question edited Jul 17, 2020 at 17:01 Boussadjra Brahim 1 asked Feb 7, 2019 at 21:53 Smokey DawsonSmokey Dawson 9,24023 gold badges85 silver badges162 bronze badges 2
  • 1 did you try v-on:input ? – Boussadjra Brahim Commented Feb 7, 2019 at 21:54
  • @BoussadjraBrahim yes that worked! thankyou – Smokey Dawson Commented Feb 7, 2019 at 21:56
Add a ment  | 

1 Answer 1

Reset to default 3

Try to use @input instead of @change event like so :

  <template>
     <div>
          <input type="text" v-model="searchTerm" v-on:input="search" />
     </div>
  </template>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745454620a4628427.html

相关推荐

  • javascript - v-on:change not calling method in nuxt.js - Stack Overflow

    This seems like a simple thing to do so I'm not exactly sure what I'm doing wrong here, I fol

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信