I am seeking a way to have certain data in my single file component shared among all instances on the page, similar to how static variables work in PHP/C.
To achieve this, I understand that in single file components, we declare data
as a function like so:
export default {
data(){
return {
// props here
};
}
}
On the other hand, in page scripts, we can define data as an object:
const app = new Vue({
data: {
// props here
},
}
The reason for this distinction is that by defining data as a function in single file components, each instance will have its own data. In contrast, when using page script, there is typically only one instance present.
I am looking for a solution to define some of my single file component data to be shared between instances while keeping other data specific to each individual instance. Is there a method to accomplish this?