computed

Properties in computed properties do not need to be defined in data and must have a return

data(){
	return{
    	firstname:"Bababa".lastname:"Lone"}}computehd(){
	fullname(){
    	return this.firstname+this.lastname
    }
}
Copy the code

As the name implies, a calculated attribute is another attribute computed from other variables. FullName recalculates its value when the two variables it depends on change. ** Computed attributes are cached, and computed attributes are cached based on their dependencies. ** The evaluated property is reevaluated only if its associated dependencies change. This means that as long as neither lastName nor firstName is changed, multiple visits to the fullName computed attribute will immediately return the previous computed result without having to execute the function again. That is, computed has multiple dependencies on its variables, uses multiple this. XXX in its functions, and triggers the function whenever one of them changes

watch

The value in the watch listener needs to be defined in data, and the function has arguments, newval and oldval

data: {
  firstName: 'Foo'.lastName: 'Bar'.fullName: 'Foo Bar'
},
watch: {
  firstName: function (val) {
    this.fullName = val + ' ' + this.lastName
  },
  lastName: function (val) {
    this.fullName = this.firstName + ' ' + val
  }
}
Copy the code

The listener watch listens for a specific value and executes a specific function when that value changes. Watch has a single dependency and can only monitor one variable at a time

The content of this issue is my personal understanding, may be wrong, the follow-up will improve