There are few ways to play with attributes from different lightning components. It depends how they are placed and used.
- Parent-Child relationship: Suppose these two components are in parent-child relationship.
A. Pass value from Parent to Child: (Containment): You can define attribute in Parent component and pass the same attribute in child component. Any changes made to child's attribute it will be reflected back to the parent component.
<aura:attribute type="Object" name="parentAttribute"/>
B. Pass value from Child to Parent: (Component Events) : Fire an Event from Child which is captured by parent and parent gets values from a child in event params.
Basically here child fires the event whenever its data change or it wants the parent components to get the updated value.
You can read more about it here: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_component.htm
2. Pass Values Unrelated Components(Application Events):
Suppose you have multiple components in your dom, you added them via App builder and now you want they should be able to pass values amongst themselves. There is no relationship between them except the fact they are sitting inside a container (assume lightning one.app container). Application event comes to your rescue.
- COOKIE (Risky): Yes You can use cookie to store values that can be savedthe in browser and can be viewed by any component. You can also set the expiry and thus they expire and doesn't provide extra access. Cookies are Locker Services Safe
Code: To store cookie.
var key = component.get("v.key");
var value = component.get("v.value");
document.cookie = key+'='+value;
4. Local Storage:(Super Risky) It's even simpler to store values in local storage. You need to have to clear them manually when not needed as there is no expiry date.