PhoenixVapor.Vue (PhoenixVapor v0.6.1)

Copy Markdown View Source

Load Vue Single File Components (.vue files) as LiveView function components.

Usage

defmodule MyAppWeb.Components do
  use Phoenix.Component

  PhoenixVapor.Vue.component :card, "vue/Card.vue"
  PhoenixVapor.Vue.component :dashboard, "vue/Dashboard.vue"
end

The path is relative to the module's file, and can be any expression known at compile time, such as Path.join(@templates, "Card.vue").

This compiles the Vue template at compile time via Vize.split_template/2 and generates a function component that renders it against assigns.

The SFC's <template> block becomes the component. A <style scoped> block is compiled and exposed as __vue_css_<name>__/0, and the root element gets its scope attribute. <script> blocks are ignored.

Summary

Functions

Define a function component from a .vue file's template.

Functions

component(name, path)

(macro)

Define a function component from a .vue file's template.

Supports <style scoped> — generates scoped CSS and injects the data-v-* scope attribute into the root element.