2

I'm new to reactJS and I'm trying to make my SVG's animated in React and I am having some issues.

I got vivus from https://www.npmjs.com/package/vivus

import React from "react";
import ReactDOM from "react-dom";
import Vivus from "vivus";

export default class MySkills extends React.Component {
constructor() {
    super();
    new Vivus('my-div', {duration: 200, file: 'link/to/my.svg'});
}

render() {
    return (
        <section id="MySkills" className="mySkills">
            <div className="wrapper">
                <div id="my-div"></div>
            </div>
        </section>
    );
}
}

And this trows me an error. I think that the issue is with constructor, but I am not sure where to put the vivus object?

Error message:

Uncaught Error: Vivus [constructor]: "element" parameter is not related to an existing ID

4

1 回答 1

3

安装组件后,您必须初始化 Vivus 对象。

export default class MySkills extends React.Component {
    constructor() {
        super();

    }
    componentDidMount(){
        new Vivus('my-div', {duration: 200, file: 'link/to/my.svg'});
    }    
    render() {
        return (
            <section id="MySkills" className="mySkills">
                <div className="wrapper">
                    <div id="my-div"></div>
                </div>
            </section>
        );
    }
}
于 2016-06-30T15:13:10.380 回答