For Tailwind CSS v3 docs, click here.

Spline

A Vue wrapper component for the Spline 3D tool, providing events and auto-resizing.

API

Prop 名称类型默认值描述
scenestringThe URL or path to the Spline scene file. Required.
onLoadFunctionundefinedCallback that fires when the Spline scene loads successfully.
renderOnDemandbooleantrueEnables or disables Spline's render-on-demand optimization.
styleobject{}Custom CSS style applied to the container of the canvas.

Emits

Event NamePayload描述
errorErrorEmits if there's an error while loading the Spline scene.
spline-mouse-downanyEmits when a mouseDown event is detected in the Spline scene.
spline-mouse-upanyEmits when a mouseUp event is detected in the Spline scene.
spline-mouse-hoveranyEmits when the mouseHover event is triggered.
spline-key-downanyEmits on keyDown within the Spline scene.
spline-key-upanyEmits on keyUp within the Spline scene.
spline-startanyEmits when the Spline scene starts.
spline-look-atanyEmits when a lookAt event occurs.
spline-followanyEmits when a follow event occurs.
spline-scrollanyEmits on scroll interactions.

通过 CLI 安装

npm
pnpm
bun
yarn
npx shadcn-vue@latest add "https://registry.inspira-ui.com/spline.json"

手动安装

Install the dependencies

npm
pnpm
bun
yarn
npm install @splinetool/runtime

Component Code

You can 复制并粘贴以下代码: to create this component:

Spline.vue
ParentSize.vue

功能特性

  • Responsive Canvas: Uses a ParentSize wrapper to adjust to the parent container size.
  • Event Bindings: Exposes Spline’s mouse, keyboard, and scrolling events via Vue emits.
  • Render-On-Demand: Optionally only re-renders when necessary, optimizing performance.
  • Easy Integration: Load a Spline 3D scene by simply passing the scene prop.
  • Cleanup & Disposal: Manages resource disposal on unmount to avoid memory leaks.

感谢

  • Utilizes Spline’s runtime behind the scenes.
  • Inspired by various 3D web experiences using Spline.