PhoenixVapor.Full (PhoenixVapor v0.6.1)

Copy Markdown View Source

Full Vue component runtime in QuickBEAM.

Use via: use PhoenixVapor, file: "X.vue", runtime: :full, bundle: "..."

Compiles .vue files with Vize, bundles with Volt (resolving component imports as externals against the pre-loaded bundle), then runs the result in QuickBEAM with the full Vue runtime.

The generated LiveView callbacks are overridable. Host LiveViews can retain their own lifecycle behavior and call super/3, super/1, or super/2 to compose it with the full Vue runtime:

def mount(params, session, socket) do
  {:ok, socket} = super(params, session, socket)
  {:ok, assign_async(socket, :account, &load_account/0)}
end

def handle_event("host-event", params, socket) do
  # Handle host-owned events without dispatching them to Vue.
  {:noreply, handle_host_event(params, socket)}
end

def handle_event(event, params, socket), do: super(event, params, socket)

Usage

defmodule MyAppWeb.DialogLive do
  use MyAppWeb, :live_view
  use PhoenixVapor,
    file: "Dialog.vue", runtime: :full,
    bundle: "priv/js/reka-dialog.js",
    globals: %{"reka-ui" => "RekaDialog"}
end

Options

  • :bundle — path to a script that defines the component libraries as globals, such as one built with mix phoenix_vapor.bundle. It is read once and cached until the file changes.
  • :globals — the global each imported package is available as in the bundle. vue is always Vue.

Summary

Functions

Returns the value of a call into the component's runtime, or raises its error. Generated callbacks use it so a JavaScript exception surfaces as itself rather than as a MatchError.

Functions

unwrap!(arg)

@spec unwrap!({:ok, value} | {:error, term()}) :: value when value: term()

Returns the value of a call into the component's runtime, or raises its error. Generated callbacks use it so a JavaScript exception surfaces as itself rather than as a MatchError.