Creating your first component
Let’s build a simple counter component that demonstrates the reactivity between Vue and LiveView.Create the LiveView
Create a LiveView to handle the counter state at
lib/my_app_web/live/counter_live.ex:counter_live.ex
Adding smooth transitions
One of Vue’s strengths is its built-in transition system. Let’s enhance our counter with smooth animations and Tailwind styling.
Now your counter will smoothly animate when the value changes! This showcases how Vue’s transition system can add polish to your LiveView apps without any server-side complexity.
Key concepts
This example demonstrates several important LiveVue features:Props flow
LiveView sends the
count value to Vue as a propEvent handling
Vue emits events with
phx-click and phx-value-* attributesState management
LiveView maintains the source of truth (the counter value)
Local UI state
Vue maintains the slider value locally without server involvement
Transitions
Vue handles smooth animations purely on the client side
Efficient updates
Only changed data is sent over WebSocket using JSON Patch
Working with custom structs
When you start passing more complex data structures as props, you’ll need to implement theLiveVue.Encoder protocol:
- Only specified fields are sent to the client
- Sensitive data is protected from accidental exposure
- Props can be efficiently diffed for optimal performance
For more details, see the Component Reference documentation.
Development tips
Next steps
Now that you have your first component working, explore:Live examples
Interactive demos to see LiveVue in action
Basic usage
Learn more patterns and the ~VUE sigil
Component reference
Complete syntax documentation
FAQ
Common questions and troubleshooting