Skip to content
On this page

canvas

画布。

WARNING

暂时只支持 2d API CanvasRenderingContext2D

Props

参数类型默认值必填说明
type'2d'指定 canvas 类型

Events

事件名说明回调参数
undefined

Example

vue
<template>
  <canvas type="2d" id="my-canvas"></canvas>
</template>

<script setup lang="ts">
import { usePage } from 'evoker'

const { onReady } = usePage()

onReady(() => {
  const query = ek.createSelectorQuery()
  query
    .select('#my-canvas')
    .fields({ node: true, size: true })
    .exec(res => {
      const canvas = res[0].node
      const ctx = canvas.getContext('2d')

      const dpr = ek.getSystemInfoSync().pixelRatio
      canvas.width = res[0].width * dpr
      canvas.height = res[0].height * dpr
      ctx.scale(dpr, dpr)

      ctx.fillRect(0, 0, 100, 100)
    })
})
</script>