Skip to content
本页目录

安装引用

使用CDN

您可以通过脚本标记直接从CDN使用KAPI,比如 unpkg

html
<script src="https://unpkg.com/@ibrucekong/kapi"></script>

同样您也可以从 jsdelivr 获取资源:

html
<script src="https://cdn.jsdelivr.net/npm/@ibrucekong/kapi"></script>

使用ES Module

html
<div id='kapi-container'></div>

<script type="module">
  import KAPI from 'https://unpkg.com/@ibrucekong/kapi@0.3.1/dist/kapi.js'

  // 授权码
  const kapi = await KAPI.build('Your Auth Token')
  // 加载云流场景服务
  const scene = new kapi.Scene('kapi-container', { server: 'Your Service URL' })
  // 等待场景加载好
  const readyState = await scene.ready()
  // 打印状态
  console.log(readyState)
</script>

使用import

首先安装依赖

shell
npm i @ibrucekong/kapi --save
html
<div id='kapi-container'></div>

<script >
  import KAPI from '@ibrucekong/kapi'
  
  // 授权码
  const kapi = await KAPI.build('Your Auth Token')
  // 加载云流场景服务
  const scene = new kapi.Scene('kapi-container', { server: 'Your Service URL' })
  // 等待场景加载好
  const readyState = await scene.ready()
  // 打印状态
  console.log(readyState)
</script>

使用require

html
<div id='kapi-container'></div>

<script>
  // 在工程中引用组件
  require(["https://unpkg.com/@ibrucekong/kapi@0.3.1/dist/kapi.js"], async (KAPI) => {
    // 授权码
    const kapi = await KAPI.build('Your Auth Token')
    // 加载云流场景服务
    const scene = new kapi.Scene('kapi-container', { server: 'Your Service URL' })
    // 等待场景加载好
    const readyState = await scene.ready()
    // 打印状态
    console.log(readyState)
  })
</script>
安装引用 has loaded