I have a piece of code that looks like this:
data() {
return {
hello: "hello",
}
}
Additionally, I have created a computed property as shown below:
computed: {
serviceHello() {
return {
sayHello() {
console.log(this.hello);
},
sayHi(){
console.log("hi");
}
}
}
Upon calling my computed properties in the mounted hook like this:
this.serviceHello.sayHello(); // Output : undefined
this.serviceHello.sayHi(); // Output: "hi"
However, when I checked what is inside this
, it only displayed the content from the computed properties (sayHello
and sayHi
) without access to the values in my data. My goal is to find a way to access the data
from within my computed properties. Specifically, I want sayHello
to display the value stored in hello
from my data.