简体   繁体   English

我在检查器中看到一个空白页面和此消息“此文件是一个模板,如果您在浏览器中直接打开它,您将看到一个空白页面。”

[英]I see an empty page and this message in inspector " This file is a template and if you open it directy in the browser you will see an empty page."

I am new to reactjs and I am trying to display a local html-video inside of the react Application.我是 reactjs 的新手,我正在尝试在 react 应用程序中显示本地 html 视频。

I recive the allow request to access camera but after accept i see just an empty page , my js file is like following:我收到允许访问相机的请求,但接受后我只看到一个空白页面,我的 js 文件如下所示:

import React, { Component } from "react";

class App extends Component {
  constructor(props) {
    super(props);

    this.localVideoref = React.createRef();
  }
  render() {
    const constraints = { video: true };

    const success = stream => {
      this.localVideoref.current.srcObject = stream;
    };

    const failure = e => {
      console.log("getUserMedia Error: ", e);
    };

    navigator.mediaDevices.getUserMedia(constraints, success, failure);

    return (
      <div>
        <video ref={this.localVideoref} autoPlay />
      </div>
    );
  }
}

export default App;

Does anyone know, what I have to adjust to make this work?有谁知道,我必须调整什么才能使这项工作?

Thanks!谢谢!

I think this will work:我认为这会奏效:

class App extends React.Component {
  constructor(props) {
    super(props);

    this.localVideoref = React.createRef();
  }
  componentDidMount() {
    const constraints = { video: true };

    navigator.mediaDevices
      .getUserMedia(constraints)
      .then(res => {
        this.localVideoref.current.srcObject = res;
      });
  }
  render() {
    return (
      <div>
        <video ref={this.localVideoref} autoPlay></video>
      </div>
    );
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用cheerio 获取数据? 当我在页面源数据中看到为空时,但是当我在检查元素中看到时,我看到了数据 - how to get data with cheerio? when i see in page source data is empty, but when i see in inspect element i see the data 我在DOM中看到了element,但是在页面上没有看到他。 WP插件Jet菜单 - I see element in DOM but I don't see him on the page. WP plugin Jet Menu 我可以将空表单模板缓存为浏览器中的第二页吗? - Can I cache an empty form template as a second page in browser? 测试以查看xml中是否有空文本节点 - testing to see if you have empty text node in xml 您刷新页面的数组中的Vuejs数据为空 - Vuejs data in the array you refreshed page is empty 我需要制作一个页面,您可以在其中看到评论的开始,但是必须单击“单击更多”才能看到其余的评论 - I need to make a page where you can see the beginning of a review, but have to click on 'click more' to see the rest of the review jquery / javascript-解析URL以查看您是否在特定页面上 - jquery/javascript - parsing url to see if you're on a certain page 浏览器呈现一个空页面 - Browser rendering an empty Page 无法看到页面。 控制台中未显示任何错误 - unable to see the page. No error is being shown in console 如何使用网络浏览器检查器工具查看网站的 js 文件? - How to see js file of a website using web browser inspector tool?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM