[英]RSS doesn't render in React component
我試圖在我的網站上顯示一個RSS小部件,並且試圖從我的React組件渲染它。 但是它沒有出現。 當我嘗試將其添加到我的HTML文件時,它的底部運行良好。
我應該如何向React添加腳本標簽?
這是我的組件:
import React, { Component } from 'react';
class Blog extends Component {
render() {
return (
<div className="container">
<h1 className="page-header">Blog</h1>
<script type="text/javascript" src="https://feed.mikle.com/js/fw-loader.js" data-fw-param="52132/"></script>
</div>
);
}
}
export default Blog;
您可以嘗試將<script>
加載到render
方法之外,然后將其移至生命周期方法中-也就是說,除非您希望腳本在每次調用render
方法時都加載。 嘗試這樣的事情:
componentWillMount() {
const script = document.createElement("script");
script.src = "https://use.typekit.net/foobar.js";
// you may want to load the script asynchronously so that is is
// only executed once available
script.async = true;
document.body.appendChild(script);
}
這樣,您的<script>
應該在組件安裝之前被調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.