LiveVue module provides seamless integration between Phoenix LiveView and Vue.js components. It exposes the vue/1 component and the ~VUE sigil for rendering Vue components within LiveView templates.
Usage
To use LiveVue in your module:vue/1 component and ~VUE sigil into your module.
vue/1
Renders a Vue component within Phoenix LiveView.The component assigns map containing attributes and options
Required attributes
Name of the Vue component (e.g., “YourComponent”, “directory/Example”). The value is directly passed to the
resolve function of the createLiveVue instance (typically found in assets/vue/index.js).Optional attributes
Explicit ID of the wrapper component. If not provided, a random one will be generated. Useful to keep ID consistent in development (e.g., “vue-1”).
CSS class(es) to apply to the Vue component wrapper (e.g., “my-class” or “my-class another-class”).
Whether to render the component on the server. Defaults to the value set in config (default: true).
LiveView socket, should be provided when rendering inside LiveView.
Whether to use differential prop updates. Defaults to the value set in config (default: true).
Event handlers
Vue event handlers can be attached using thev-on: prefix:
Event handler for Vue events (e.g.,
v-on:click, v-on:input).Props and slots
All other attributes are passed as props to the Vue component. Slots can be passed as regular Phoenix slots.Examples
Basic component with props and event handler:~VUE sigil
Inlines a Vue single-file component inside a LiveView. This is the recommended way to write inline Vue components.The Vue single-file component source code as a string.
Sigil modifiers (currently must be an empty list).
Returns a HEEx template that renders the inlined Vue component.
Example
- Writes the component to
./assets/vue/_build/#{caller.module}.vue - Passes all assigns as props to the component
- Handles socket and SSR options from
vue_optsin assigns
Deprecated
~V sigil
~VUE and will be removed in a future version.