Skip to content

taro 中报错canvas not found. 代码如示例一样 #18

@wukongyang

Description

@wukongyang
import { Component } from 'react'
import { View, Text, Canvas } from '@tarojs/components'
import { Parser, Player } from "svgaplayer-weapp";

import "taro-ui/dist/style/components/button.scss" // 按需引入
import './index.scss'

export default class Index extends Component {

  componentDidMount () {
    this.loadAnimation();
  }

  async loadAnimation() {
    const parser = new Parser;
    const player = new Player;
    await player.setCanvas('#demoCanvas')
    const videoItem = await parser.load("https://cdn.jsdelivr.net/gh/svga/SVGA-Samples@master/angel.svga");
    await player.setVideoItem(videoItem);
    player.startAnimation();
  }

  render () {
    return (
      <View className='index'>
        <Canvas type='2d' id='demoCanvas' style={{width: "300px", height: "300px", backgroundColor: "black"}} />
      </View>
    )
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions