0👍
there are many ways to share data from different components:
- uex
vuex is the best way to manage your apps state,but is much more heavy for small project
- customevent
customevent is easier than vuex to cast data in your app
var event = new CustomEvent('customE', {
"detail": {
//your data here
}
})
window.dispatchEvent(event)
//get data
window.addEventListener("customE", (e)=>{
//get your data here
e.detail
});
- storage
you can use localstorage or sessionstorage to cast your data and use storage event to get your data,you will dispatch storage event as you change customData value:
localStorage.customData = JSON.stringify('your Json data')
window.addEventListener('storage', (e) => {
//make sure you filter your data key
if (e.key === 'customData') {
//get your data here
e.newValue
}
}
)
Source:stackexchange.com