react加載 外部html

將html加載器添加到您的項目中:

npm i -D html-loader
將以下規則添加到webpack.config文件中:

{
test: /.(html)$/,
use: {
loader: ‘html-loader’,
options: {
attrs: [’:data-src’]
}
}
}
現在您可以按如下方式導入html文件:

import React, { Component } from ‘react’;
import Page from ‘./test.html’;
var htmlDoc = {__html: Page};

export default class Doc extends Component {
constructor(props){
super(props);
}

render(){
return (

)
}}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章