English 中文(简体)
美人美人鱼JJS给我一个语法错误 文本每当我试图重发它时都会给我一个语法错误
原标题:Mermaid JS giving me a syntax error in text whenever I try to re-render it

error I ve been trying to use a gantt chart in my react app which works fine when it first loads up and if I refresh. However whenever I change the props and componentDidUpdate() triggers, which triggers :

 if (prevProps.chart !== this.props.chart) {
            //console.log("the state has changed comp", this.state.chart)
            document
                .getElementById("mermaid-chart")
                .removeAttribute("data-processed");
            mermaid.contentLoaded()
            
        }

我得到那个图像,强迫我更新页面

import React from "react";
import mermaid from "mermaid";


mermaid.initialize({
    startOnLoad: true,
    securityLevel: "loose",
    gantt: {
        barHeight: 40,
        barGap: 15,
        sectionFontSize: 20,
        leftPadding: 200,
        numberSectionStyles: 2,
        fontSize: 15,
    }
});


export default class Mermaid extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            chart: props.chart,
        };
    }

    componentDidMount() {
        //console.log("comp mounted")
        mermaid.contentLoaded();
    }

    componentDidUpdate(prevProps, prevState) {
         //console.log("the state has not changed comp", prevProps.chart);
        // console.log("the current state has not changed comp", this.props.chart);
        if (prevProps.chart !== this.props.chart) {
            //console.log("the state has changed comp", this.state.chart)
            document
                .getElementById("mermaid-chart")
                .removeAttribute("data-processed");
            mermaid.contentLoaded()
            
        }
    }
    render() {
        return <div className="mermaid" id="mermaid-chart">{this.state.chart}</div>;
    }

This is what my code is looking like, in my component I have return (<Mermaid chart={chart} />)

当我使用旧版的Mermaid.js时,它告诉我它试图用文字来绘制一个图表:“ & lt; svg id =. ” 我认为发生这种情况是因为它试图让 div 的第一个孩子返回,而我不知道如何让它去制造道具。

任何帮助都会很有帮助的

问题回答

不久前得到的,这里是最新消息 以防将来有人发现

 componentDidMount() {
        
        mermaid.contentLoaded();
    }

    async drawDiagram(chart) {
    let element = document.querySelector("#mermaid-container");
    
    const graphDefinition = chart
    
    const { svg } = await mermaid.render("mermaid-chart", graphDefinition);
    
    element.innerHTML = svg;
    }

    async componentDidUpdate(prevProps, prevState) {
         this.props.chart);
        if (prevProps.chart !== this.props.chart) {
            

            await this.drawDiagram(this.props.chart);
  
        }
    }

    render() {
        return (
            <div className="mermaid" id="mermaid-chart">
                {this.state.chart}
            </div>
        );
    }




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签