当我在我的 nextjs 项目中安装 tailwind css 时 innerHTML 不工作

问题描述 投票:0回答:0

我正在尝试将 innerHTML 插入到 div 中,但它无法正常工作。它只显示文本,就好像它是在没有任何标签的情况下插入的一样。在我的 nextjs 项目中安装 tailwind css 之前它工作正常。安装后,我无法显示使用 h2、ol 等标签设计的插入文本

import Head from 'next/head'
import { useEffect, useRef } from 'react'

export default function Home() {
  const contentRef = useRef<HTMLDivElement>(null)
  useEffect(()=> {
    if (contentRef.current) {
      contentRef.current.innerHTML = '<h1>Hello</h1>'
    }
  })
  return (
    <>
      <Head>
        <title>Create Next App</title>
        <meta name="description" content="Generated by create next app" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <main>
         <div ref={contentRef}></div>
      </main>
    </>
  )
}
next.js tailwind-css innerhtml
© www.soinside.com 2019 - 2024. All rights reserved.