【发布时间】:2020-10-28 17:31:00
【问题描述】:
App.html
<!DOCTYPE html>
<html>
<head>
<title>Carousel</title>
<link rel="stylesheet" type="text/css" href="./css/materialize.min.css">
</link>
<link rel="stylesheet" type="text/css" href="App.css">
</link>
</head>
<div class="carousel">
<div class="carousel-item">
<img src={require("./1.png")} class="responsive-img"></img>
</div>
<div class="carousel-item">
<img src={require("./2.png")} class="responsive-img"></img>
</div>
<div class="carousel-item">
<img src={require("./3.png")} class="responsive-img"></img>
</div>
<script src="./js/materialize.min.js"></script>
<script>
const small = document.querySelector('.carousel');
var inst = M.Carousel.init(small, {});
inst.dist(50);
</script>
</div>
</html>
App.js
import React from 'react';
var perf = require('./App.html');
class App extends React.Component {
render(){
return (
<div dangerouslySetInnerHTML={{ __html: perf }} ></div>
);
}
}
export default App;
有人可以帮助我如何在我的 JS 文件中添加 HTML 文件并通过我的 JS 文件运行 HTML 文件。我已经使用 HTML 中的物化制作了一个轮播,但是我无法在 JS 中编写代码,因此,如果可能的话,有人可以帮助我将 HTML 文件转换为 JS 文件,或者如何导入 HTML 文件在我的 JS 文件中。
【问题讨论】:
-
为什么不创建
<Carousel/>组件并将所有必要的标记和依赖项放在那里?
标签: javascript html node.js reactjs