Vue mustache portion not updated

Asked 2 years ago, Updated 2 years ago, 83 views

I'm trying to update the display using Vue's monitoring properties, but when I change the text in input, the {{newMessage}} and {{oldMessage}} parts below are not updated. ({{message}} parts are updated.)
I'm sorry to ask you a rudimentary question, but please let me know when you know how it works.

HTML

<p>
  {{ message}}}/updated with input value
  {{ newMessage}}/null Remain Unupdated
  {{ oldMessage}}//null does not update
</p>
<input type="text" v-model="message"/>
<pre>
  {{ $data}} // newMessage, oldMessage value not updated
</pre>

JavaScript

 var app = new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue.js!',
    newMessage:',
    oldMessage: ''
    },
  watch: {
    message:(newValue, oldValue) = > {
    This.newMessage=newValue
    This.oldMessage=oldValue
    console.log(this.newMessage, newValue) // Both new values are displayed on the console
    }
  }
})    

javascript vue.js

2022-09-30 10:55

1 Answers

Inside the watch

 message:function(newValue, oldValue){
   ...
}

as

Unlike functions by function, the Arrow function this is determined at generation.Therefore, this is not the Vue instance you expect

to be.


2022-09-30 10:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.