Vue Connect Tech 2019 - ChoDragon9/posts GitHub Wiki
Composing functionality With the New Vue Apis
What is the goal of the composition API?
- Portable functionality
- Composable abstractions
The Main Benefits
- Explicit extraction of logic, including stateful logic
- Feature based organization vs. Option-based organization
μνκ΄λ¦¬
https://www.vuemastery.com/conferences/connect-tech-2019/managing-state-in-vuejs
What is Vuex?
- Store Model for State
- Reduces the paths where data is mutated
- Introduces more concepts (complexity)
Flow
Vue Components =[Dispatch]=> Actions =[Commit]=>
Mutations =[Mutate]=> State =[Render]=> Vue Components
Vue μ»΄ν¬λνΈμ μνκ΄λ¦¬λ Vuexλ₯Ό ν΅ν΄μ νλ€.
μ»΄ν¬λνΈ λμμΈ ν¨ν΄
https://www.vuemastery.com/conferences/connect-tech-2019/fundamental-component-design-patterns/
[Props-based solution] Problems
- New requirements increase complexity
- Multiple responsibilities
- Lots of conditionals in the template
- Low flexibility
- Hard to maintain
Use slots for:
- Content distribution (like layouts)
- Creating larger components by combining smaller components
- Default content in Multi-page Apps
- Providing a wrapper for other components
- Replace default component fragments
Use scoped slots for:
- Applying custom formatting/template to fragments of a component
- Creating wrapper components
- Exposing its own data and methods to child components
Slots(Composition) > Props(Configuration)
- Slots: With composition, you're less restricted by what you are building at first.
- Props: With configuration, you have to document everything and new requirements means new configuration
Container (What is it doing?)
Examples: UserProfile, Product, TheShoppingCart, Login
- Application logic
- Application state
- Use Vuex
- Usually Router views
Presentational (How does it look?)
Examples: AppButton, AppModal, TheSidebar, ProductCard
- Application UI and styles
- UI-related state only
- Receive data from props
- Emit events to containers
- Reusable and composable
- Not relying on global state
Propsλ₯Ό ν΅ν μ»΄ν¬λνΈ λμμΈμ 볡μ‘νλ€. Slotμ ν΅ν΄ ν΄κ²°ν μ μλ€.
Scoped slotsμ μ¬μ©νλ©΄ μμ μ»΄ν¬λνΈμ μ λ¬ν μνλ₯Ό λΆλͺ¨μμ μ¬μ©ν μμλ€. λ°λ³΅μ λν μ²λ¦¬λ₯Ό μμμμ νκ³ λΆλͺ¨λ μ΄λ€ κ²μ νμν μ§ μ νν μ μλ€.
λ§μ§λ§μ₯μ―€μλ μΈμ 리ν©ν λ§μ΄ νμνκ°μ λν λ΄μ©λ λ€λ£¬λ€.