@codatum/embed-vue

中文文档
1.0.0发布于 2026/03/03Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 6180

Vue 3 integration for Codatum signed embedding

原始使用文档
文档目录11 节
  1. Installation
  2. Usage
  3. Calling reload from the parent
  4. Changing props at runtime
  5. Custom loading UI ( #loading slot)
  6. API
  7. Props
  8. Slots
  9. Events
  10. Expose (ref)
  11. See also

@codatum/embed-vue

Vue 3 integration for Codatum Signed Embed. Provides a single component that wraps the core SDK. All of @codatum/embed is re-exported so you can use this package as a single entry point (one version, no split).

For options, types, events, and programmatic API details, see @codatum/embed.

Installation

pnpm add @codatum/embed-vue
# or
npm install @codatum/embed-vue

Requires Vue 3 (peer dependency).

Usage

<script setup lang="ts">
import { EmbedVue } from "@codatum/embed-vue";

const embedUrl = "https://app.codatum.com/protected/workspace/xxx/notebook/yyy";
const tokenProvider = async () => {
  const res = await fetch("/api/embed-token", { method: "POST" });
  const data = await res.json();
  return { token: data.token };
}
</script>

<template>
  <EmbedVue
    :embedUrl="embedUrl"
    :tokenProvider="tokenProvider"
    :iframeOptions="{ theme: 'LIGHT', locale: 'ja' }"
    @statusChanged="(e) => console.log('Status', e.status)"
    @paramChanged="(e) => console.log('Params', e.params)"
    @executeSqlsTriggered="(e) => console.log('Execute', e.params)"
    @error="(e) => console.error(e)"
  />
</template>

Calling reload from the parent

Use a template ref and call the exposed reload() method. It returns true on success and false on failure (errors are emitted via @error; it does not throw).

<script setup lang="ts">
import { ref } from "vue";
import { EmbedVue } from "@codatum/embed-vue";

const embedRef = ref<InstanceType<typeof EmbedVue> | null>(null);

async function onFilterChange() {
  const ok = await embedRef.value?.reload();
  if (!ok) console.warn("reload failed — see @error");
}
</script>

<template>
  <EmbedVue ref="embedRef" :embedUrl="..." :tokenProvider="..." @error="handleError" />
</template>

Changing props at runtime

Props are read once at mount. To apply new values (e.g. a different embedUrl or iframeOptions), use :key to force a remount:

<EmbedVue :key="embedUrl" :embedUrl="embedUrl" :tokenProvider="tokenProvider" />

Custom loading UI (#loading slot)

When you pass the #loading slot, the component hides the iframe during loading (init, reload, token refresh, etc.) and shows your custom UI as an overlay. Use showLoadingOn to control which statuses show the overlay (default: ['INITIALIZING', 'RELOADING', 'REFRESHING']). Without the slot, the built-in iframe loading behavior is unchanged.

<!-- Spinner for all loading states -->
<EmbedVue :embedUrl="embedUrl" :tokenProvider="tokenProvider">
  <template #loading>
    <MySpinner />
  </template>
</EmbedVue>

<!-- Only on first load -->
<EmbedVue
  :embedUrl="embedUrl"
  :tokenProvider="tokenProvider"
  :showLoadingOn="['INITIALIZING']"
>
  <template #loading>
    <MySpinner />
  </template>
</EmbedVue>

<!-- Branch by status -->
<EmbedVue :embedUrl="embedUrl" :tokenProvider="tokenProvider">
  <template #loading="{ status }">
    <FullPageLoader v-if="status === 'INITIALIZING'" />
    <SubtleBar v-else />
  </template>
</EmbedVue>

API

Option types and behavior (e.g. iframeOptions, tokenOptions, displayOptions, devOptions) are the same as in @codatum/embed. The component uses its root element as the iframe container (no container prop).

Props

PropRequiredType
embedUrlYesstring
tokenProviderYes(context: TokenProviderContext) => Promise<TokenProviderResult>
iframeOptionsNoIframeOptions
tokenOptionsNoTokenOptions
displayOptionsNoDisplayOptions
devOptionsNoDevOptions
showLoadingOnNoEmbedStatus[] — Which statuses show the loading overlay. Default: ['INITIALIZING', 'RELOADING', 'REFRESHING']. Ignored when #loading slot is not set.

Slots

SlotScoped PropsDescription
#loading{ status: EmbedStatus }Custom UI shown while loading. Overlay is shown (and iframe hidden) only when this slot is provided and the current status is in showLoadingOn. Without the slot, built-in iframe loading behavior is used.

Events

EventPayloadWhen
statusChanged{ type: 'STATUS_CHANGED', status: EmbedStatus, previousStatus: EmbedStatus }See core SDK
paramChanged{ type: 'PARAM_CHANGED', params: EncodedParam[] }See core SDK
executeSqlsTriggered{ type: 'EXECUTE_SQLS_TRIGGERED', params: EncodedParam[] }See core SDK
executionSucceeded{ type: 'EXECUTION_SUCCEEDED' }See core SDK
executionFailed{ type: 'EXECUTION_FAILED', errorMessage: string }See core SDK
errorEmbedErrorInit, reload, or token auto-refresh failed

Expose (ref)

PropertyTypeDescription
reload()() => Promise<boolean>Re-fetches token and params; returns false on failure (error emitted via @error)
status'CREATED' | 'INITIALIZING' | 'RELOADING' | 'REFRESHING' | 'READY' | 'DESTROYED'Current embed state

Need a custom container or full control? Use createEmbed() from this package (or @codatum/embed) in onMounted and instance.destroy() in onUnmounted.

See also

版本与发布记录

@codatum/embed-vue 共发布 10 个版本,首次发布于 2026/02/20;过去 12 个月发布了 10 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.0latest2026/03/038 个月前
0.5.22026/03/038 个月前
0.5.12026/03/038 个月前
0.5.02026/03/038 个月前
0.4.02026/03/028 个月前
0.3.02026/02/248 个月前

关于 @codatum/embed-vue 的常见问题

@codatum/embed-vue 是什么?

Vue 3 integration for Codatum signed embedding

如何安装 @codatum/embed-vue?

在项目目录运行 npm install @codatum/embed-vue,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(>=3.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@codatum/embed-vue 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codatum/embed-vue 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@codatum/embed-vue 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@codatum/embed-vue 可以商用吗?

@codatum/embed-vue 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@codatum/embed-vue 的下载量有多少?

根据 npm 官方下载统计,@codatum/embed-vue 在 2026/10/10 – 2026/11/08 这 30 天内被下载 6,180 次,日均约 206 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codatum/embed-vue 还在维护吗?

最新版本 1.0.0 发布于 2026/03/03(8 个月前);至今共发布 10 个版本,其中过去 12 个月发布了 10 个;首次发布于 2026/02/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。