Can I pass parameters in computer properties in Vue.js?

Technology CommunityCategory: Vue.jsCan I pass parameters in computer properties in Vue.js?
VietMX Staff asked 3 years ago

You can use a method or computed function.

The method way:

<span>{{ fullName('Hi') }}</span>

methods: {
  fullName(salut) {
      return `${salut} ${this.firstName} ${this.lastName}`
  }
}

Computed property with a parameter way:

computed: { 
	fullName() {
		return salut => `${salut} ${this.firstName} 		
		 ${this.lastName}`
    }
}