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 (

)
}}

发布了55 篇原创文章 · 获赞 12 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/mrzhangdulin/article/details/103011078