General questions
Why LiveVue?
Why LiveVue?
Phoenix LiveView makes it possible to create rich, interactive web apps without writing JS. However, when you need complex client-side functionality, you might end up writing lots of imperative, hard-to-maintain hooks.LiveVue allows you to create hybrid apps where:
- Server maintains the session state
- Vue handles complex client-side interactions
- Both sides communicate seamlessly
- Your hooks are starting to look like jQuery
- You have complex local state to manage
- You want to use the Vue ecosystem (transitions, graphs, etc.)
- You need advanced client-side features
- You simply like Vue 😉
What's with the name?
What's with the name?
Yes, “LiveVue” sounds exactly like “LiveView” - we noticed slightly too late to change! Some helpful Reddit users pointed it out 😉We suggest referring to it as “LiveVuejs” in speech to avoid confusion.
Technical details
How does LiveVue work?
How does LiveVue work?
The implementation is straightforward:For a deeper dive into the architecture, see Architecture.
-
Rendering: Phoenix renders a
divwith:- Props as data attributes
- Slots as child elements
- Event handlers configured
- SSR content (when enabled)
-
Initialization: The LiveVue hook:
- Mounts on element creation
- Sets up event handlers
- Injects the hook for
useLiveVue - Mounts the Vue component
-
Updates:
- Phoenix updates only changed data attributes
- Hook updates component props accordingly
-
Cleanup:
- Vue component unmounts on destroy
- Garbage collection handles cleanup
Hooks fire only after
app.js loads, which may cause slight delays in initial render.What optimizations does LiveVue use?
What optimizations does LiveVue use?
LiveVue implements several performance optimizations:1. Selective updatesOnly changed props/handlers/slots are sent to client, achieved through careful String interpolation prevents sending
__changed__ assign modifications.2. Efficient props handlingdata-props= on each update.3. Struct encoding and diffing- Uses
LiveVue.Encoderprotocol to convert structs to maps - Enables efficient JSON patch calculations (using Jsonpatch library)
- Reduces payload sizes by sending only changed fields
What is the LiveVue.Encoder protocol?
What is the LiveVue.Encoder protocol?
The For complete implementation details including field selection, custom implementations, and third-party structs, see Basic usage.The protocol is similar to
LiveVue.Encoder protocol is a crucial part of LiveVue’s architecture that safely converts Elixir structs to maps before JSON serialization.Why it’s needed:- Security: Prevents accidental exposure of sensitive struct fields
- Performance: Enables efficient JSON patch diffing by providing consistent data structures
- Explicit control: Forces developers to be intentional about what data is sent to the client
Jason.Encoder but converts structs to maps instead of JSON strings, which allows LiveVue to calculate minimal diffs and send only changed data over WebSocket connections.Why is SSR useful?
Why is SSR useful?
SSR (Server-Side Rendering) provides several benefits:
- Initial render: Components appear immediately, before JS loads
- SEO: Search engines see complete content
- Performance: Reduces client-side computation
- SSR runs only during “dead” renders (no socket)
- Not needed during live navigation
- Can be disabled per-component with
v-ssr={false}
Can I nest LiveVue components inside each other?
Can I nest LiveVue components inside each other?
No, it is not possible to nest a
<.vue> component rendered by LiveView inside another <.vue> component’s slot.Why?This limitation exists because of how slots are handled. The content you place inside a component’s slot in your .heex template is rendered into raw HTML on the server before being sent to the client. When the parent Vue component is mounted on the client, it receives this HTML as a simple string.Since the nested component’s HTML is just inert markup at that point, Phoenix LiveView’s hooks (including the VueHook that powers LiveVue) cannot be attached to it, and the nested Vue component will never be initialized.Workarounds:-
Adjacent components: The simplest approach is to restructure your UI to use adjacent components instead of nested ones.
-
Standard Vue components: You can nest standard (non-LiveVue) Vue components inside a LiveVue component. These child components are defined entirely within the parent’s Vue template and do not have a corresponding
<.vue>tag in LiveView.
Development
How do I use TypeScript?
How do I use TypeScript?
LiveVue provides full TypeScript support out of the box. The Igniter installer sets up TypeScript automatically with proper configuration for:LiveVue uses Vite which provides built-in TypeScript support with no additional configuration needed.
- Vue single-file components with
<script setup lang="ts"> - Type-safe props with
defineProps<T>() - LiveVue composables with full type inference
app.js, since it’s harder to convert directly:Where should I put Vue files?
Where should I put Vue files?
Vue files in LiveVue are similar to HEEX templates. You have two main options:
- Default location:
assets/vuedirectory - Colocated: Next to your LiveViews in
lib/my_app_web
- Keeping related code together
- Making relationships clearer
- Simplifying maintenance
.vue files in lib/my_app_web and reference them by name or path.For advanced component organization, see Configuration.Comparison with other solutions
How does LiveVue compare to LiveSvelte?
How does LiveVue compare to LiveSvelte?
Both serve similar purposes with similar implementations, but have key differences:Technical differences:
- Vue uses virtual DOM, Svelte doesn’t
- Vue bundle is slightly larger due to runtime
- Performance is comparable
- Svelte: Compilation-based, concise but with some limitations
- Vue: Proxy-based, more verbose but more predictable
- Vue is working on Vapor mode (no virtual DOM)
- Svelte 5 Runes will be similar to Vue
ref
- Vue has a larger ecosystem
- More third-party components available
- Larger community
- Your team’s familiarity
- Ecosystem requirements
- Syntax preferences
- Bundle size concerns
Additional resources
- LiveVue Examples - Live demo website with interactive examples
- GitHub Discussions
- Vue Documentation
- Phoenix LiveView Documentation