React-Bootstrap 响应式嵌入组件
React-Bootstrap 是一个前端框架,旨在牢记反应。 ResponsiveEmbed 组件很有用,因为它基于容器块的宽度,它允许浏览器确定幻灯片或视频的尺寸。我们可以在 ReactJS 中使用以下方法来使用 react-bootstrap ResponsiveEmbed 组件。
响应式嵌入道具:
- aspectRatio:用于设置嵌入的纵横比。
- children:用于定义该组件的单个子元素。
- bsPrefix:它是使用高度定制的引导 CSS 的逃生舱口。
创建 React 应用程序并安装模块:
第 1 步:使用以下命令创建一个 React 应用程序:
npx create-react-app foldername
第 2 步:创建项目文件夹(即文件夹名称)后,使用以下命令移动到该文件夹:
cd foldername
第 3 步:创建 ReactJS 应用程序后,安装 必需的 模块使用以下命令:
npm install react-bootstrap npm install bootstrap
项目结构:它将如下所示。
示例:现在在App.js文件中写下以下代码。在这里,App 是我们编写代码的默认组件。
App.js
import React from 'react';
import 'bootstrap/dist/css/bootstrap.css';
import ResponsiveEmbed from 'react-bootstrap/ResponsiveEmbed'
export default function App() {
return (
React-Bootstrap ResponsiveEmbed Component
);
}
运行应用程序的步骤:从项目的根目录使用以下命令运行应用程序:
npm start
输出:现在打开浏览器并转到http://localhost:3000/ ,您将看到以下输出:
参考: https://react-bootstrap.github.io/utilities/responsive-embed/