ARTS - Week Five
42. Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
Vue 2 props and emit - parent to child
The correct way to use props and $emit
OK, so what’s correct way ? we want component reusable, it should pure. Following is the flow what vue design.
Parent has data to control, pass data to child component by props.
If child component need to deal with props data, assign props data value to itself’s data when component mounted.
After handle method, parent open a interface to child. Child $emit back new value to parent.
(every component has it scope and data.)
Dynamic directive arguments
One of the coolest features of Vue 2.6 is the possibility to pass down directive arguments to a component dynamically. Imagine you have a Button-Component and want to listen to a Click-Event in some cases but to a DoubleClick-Event in other cases. That's where those directives come in handy:
7 Simple VueJS Tips You Can Use to Become a Better Developer
1. Use one component in multiple routes
2. The $on(‘hook:’) can help simplify your code
3. $on can also listen to a child component’s lifecycle hooks
4. Use immediate: true to trigger watchers on initialization
5. You should always validate your props…please.
6. Passing all props to a child component is easy
7. You HAVE TO understand all the component options
when would I use a watcher?
Observing a value until it reaches a specific value
Making an asynchronous API call when a value changes
You don’t need to combine existing data into a new property
VueJS Lifecycle Hooks
Using the beforeCreate hook is useful when you need some sort of logic/API call that does not need to be assigned to data.
Mounting Hooks – Accessing the DOM
Update Hooks – Reactivity in the VueJS Lifecycle
Destruction Hooks – Cleaning Things Up
How to Manage VueJS Mixins