Today I Learned - Rocky Kev

TIL Getting parent data from child component

POSTED ON:

TAGS:

Access Parent Data( ) from Child Components

Sometimes we want to access data from a parent, but don’t want to go through the hassle of passing props.
If you just need to grab a quick value from a $parent’s data object, you can do it simply by referencing $parent:


// In parent
data() {
return {
message: 'This is my message'
}
}

// In child template
<div></div> // <-- results in 'This is my message'

11 Advanced Vue Coding Tricks


Related TILs

Tagged:

TIL How to implement two-way binding without a framework

One of the reasons we use React or Vue is because of that sweet sweet two-way binding. It's the automatic syncing of data between the model (data) and the view (UI) in both directions. Any changes made to the data will automatically update the view, and any changes made to the view will automatically update the data.

TIL Cherry-picking out of bootstrap-vue

If you are using a component library that uses ES modules like bootstrap-vue, you can cherry pick its components instead of just registering all of them globally.

TIL how Svelte is different fom Vue/React