视频标签与create-react-app项目作出反应

Ase*_*ela 1 javascript reactjs create-react-app

我在向项目添加本地视频时遇到问题

<video src={import(src/assets/abc.mp4)} type="video/mp4"/>
Run Code Online (Sandbox Code Playgroud)

我研究过并发现了

网络包配置

使这成为可能但我无法弄清楚如何将它介绍到create-react-app项目.

我无法为我的视频进行云托管,因为我在移动版本上也需要它.请问有人可以帮忙吗?

Dan*_*mov 5

您尝试使用的语法(动态import())用于代码拆分,而不是用于添加文件.
我不确定你为什么要寻找Webpack配置,因为它支持开箱即用.

请按照解释如何导入资产的官方文档:

// Assuming abc.mp4 is in the same folder as this component
import myVideo from './abc.mp4';
// This will become a string with the path to the video at build time

// Your component definition
export default function MyComponent() {
  return <video src={myVideo} type="video/mp4" />;
}
Run Code Online (Sandbox Code Playgroud)

  • 这适用于图像很好,但不可否认的是,我在为视频做同样的事情时遇到了麻烦.视频永远不会使用此代码加载,尽管视频网址有效并且如果放在浏览器中则会加载.有没有人有这个问题? (2认同)