Skip to content

v-model to a computed properties, when <input> on blur, the value is reset  #5281

@Rockson

Description

@Rockson

Version

2.2.5

Reproduction link

https://github.com/Rockson/vue-error-computed

Steps to reproduce

<template>
  <input class="input" type="number" v-model="Year">
</template>

<script>
  export default {
    data () {
      return {
        date: new Date()
      }
    },
    computed: {
      Year: {
        get: function () {
          console.log(`get: ${this.date}`)
          return this.date.getFullYear()
        },
        set: function (year) {
          this.date.setFullYear(year)
          console.log(`set: ${this.date}`)
        }
      }
    }
  }
</script>

Start the dev server and go to the root. On the browser, change the input content then blur the input.

the actual code is in src/components/Hello.vue

see also #3389

What is expected?

I expect the get method to be called after keyup

What is actually happening?

It won't call the get method after keyup, It will erase the changes in the input after blur

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions