Kết xuất HTML thô có nguy cơ của riêng bạn!
Định nghĩa bài vănĐây là một bài đăng trên blog giải thích chi tiết hơn:
TL;DRReact sử dụng Khi bạn sử dụng Hành vi này có vẻ rất kỳ quặc đối với tôi (ý tôi là tên chống đỡ chứa từ import React from 'react' import InnerHTML from 'dangerously-set-html-content' function Example { const html = ` <div>This wil be rendered</div> <script> alert('testing') </script> ` return ( <InnerHTML html={html} /> ) }0, và bạn cũng cần phải truyền một đối tượng với import React from 'react' import InnerHTML from 'dangerously-set-html-content' function Example { const html = ` <div>This wil be rendered</div> <script> alert('testing') </script> ` return ( <InnerHTML html={html} /> ) }1, có mục đích, vì vậy bạn thực sự biết những gì bạn đang làm) , vẫn không giải quyết vấn đề của tôi Sau một chút tìm kiếm, tôi thấy rằng import React from 'react' import InnerHTML from 'dangerously-set-html-content' function Example { const html = ` <div>This wil be rendered</div> <script> alert('testing') </script> ` return ( <InnerHTML html={html} /> ) }2 có một thứ gọi là phạm vi, API này cho phép bạn tạo một đoạn của tài liệu, vì vậy sử dụng mà tôi đã tạo import React from 'react' import InnerHTML from 'dangerously-set-html-content' function Example { const html = ` <div>This wil be rendered</div> <script> alert('testing') </script> ` return ( <InnerHTML html={html} /> ) }3. Thành phần React này hiển thị HTML từ một chuỗi, với điểm cộng thực thi tất cả các mã JS mà HTML chứa !! 🎉 🚨🚨 Sử dụng nó có nguy cơ của riêng bạn🚨🚨USE IT AT YOUR OWN RISK🚨🚨 Cài đặtyarn add dangerously-set-html-content // or // npm install --save dangerously-set-html-content Cách sử dụngimport React from 'react' import InnerHTML from 'dangerously-set-html-content' function Example { const html = ` <div>This wil be rendered</div> <script> alert('testing') </script> ` return ( <InnerHTML html={html} /> ) } Điều này cũng sẽ hoạt động cho các tập lệnh với thuộc tính import React from 'react' import InnerHTML from 'dangerously-set-html-content' function Example { const html = ` <div>This wil be rendered</div> <script> alert('testing') </script> ` return ( <InnerHTML html={html} /> ) }4 đặt nó Sự phát triểnSau khi nhân bản repo và cài đặt tất cả các DEP, bạn có thể làm cho thư mục import React from 'react' import InnerHTML from 'dangerously-set-html-content' function Example { const html = ` <div>This wil be rendered</div> <script> alert('testing') </script> ` return ( <InnerHTML html={html} /> ) }5 để cài đặt các phụ thuộc ví dụ (gói sẽ là một liên kết với tệp trong import React from 'react' import InnerHTML from 'dangerously-set-html-content' function Example { const html = ` <div>This wil be rendered</div> <script> alert('testing') </script> ` return ( <InnerHTML html={html} /> ) }6) Khi bạn đang sử dụng thư mục đó, bạn có thể chạy:
Và một ví dụ tất cả sẽ được mở. Chạy kiểm tra đơn vịRun:
Giấy phépMIT © Christo-pr Kết xuất HTML RAW theo rủi ro của riêng bạn! React đã có Khi bạn sử dụng Khi ăn xin hành vi này có vẻ rất kỳ quặc đối với tôi (ý tôi là tên đạo cụ chứa từ Sau một chút tìm kiếm, tôi thấy rằng import React from 'react' import InnerHTML from 'dangerously-set-html-content' function Example { const html = ` <div>This wil be rendered</div> <script> alert('testing') </script> ` return ( <InnerHTML html={html} /> ) }2 có một thứ gọi là phạm vi, API này cho phép bạn tạo một đoạn của tài liệu, do đó, sử dụng mà tôi tạo import React from 'react' import InnerHTML from 'dangerously-set-html-content' function Example { const html = ` <div>This wil be rendered</div> <script> alert('testing') </script> ` return ( <InnerHTML html={html} /> ) }3 lib. Đây là một thành phần phản ứng hiển thị HTML từ một chuỗi, với điểm cộng thực thi tất cả các mã JS mà HTML chứa !! 🚨🚨 Sử dụng nó bằng rủi ro của riêng bạnUSE IT BY YOUR OWN RISK🚨🚨 Cài đặtyarn add dangerously-set-html-content // or // npm install --save dangerously-set-html-content Cách sử dụngimport React from 'react' import InnerHTML from 'dangerously-set-html-content' function Example { const html = ` <div>This wil be rendered</div> <script> alert('testing') </script> ` return ( <InnerHTML html={html} /> ) } Điều này cũng sẽ hoạt động cho các tập lệnh với thuộc tính import React from 'react' import InnerHTML from 'dangerously-set-html-content' function Example { const html = ` <div>This wil be rendered</div> <script> alert('testing') </script> ` return ( <InnerHTML html={html} /> ) }4 đặt nó Giấy phépMIT © Christo-pr |