LiveVue
1.0
Counter
The classic counter example demonstrating the core LiveVue pattern: server state flows down as props, user interactions bubble up as events.
What this example shows
How it works
1 Props flow from LiveView to Vue
The count
assign in LiveView
becomes a prop in Vue. When the server state changes, Vue automatically re-renders with the new value.
<.vue count={@count} v-component="Counter" v-socket={@socket} />
2 Local state stays in Vue
The diff
slider value is managed entirely in Vue
using ref(). No server round-trip for UI-only state.
const diff = ref(1) // Local Vue state
3 Phoenix bindings work in Vue templates
Standard Phoenix event bindings like
phx-click
work directly in Vue templates. Use Vue's
:phx-value-*
binding
to pass dynamic values.
<button phx-click="inc" :phx-value-diff="diff">+{{ diff }}</button>
4 Vue transitions on server updates
Vue's <Transition>
component animates when props change from the server. The
:key
binding triggers the transition on each value change.
<Transition name="count" mode="out-in">
<div :key="props.count">{{ props.count }}</div>
</Transition>