如何在React中设置文档标题?

编程入门 行业动态 更新时间:2024-10-28 10:22:46
本文介绍了如何在React中设置文档标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想为我的React应用程序设置文档标题(在浏览器标题栏中)。我尝试过使用 react-document-title (似乎已过期)并设置 document.title 在构造函数和 componentDidMount() - 没有这些解决方案有效。

I would like to set the document title (in the browser title bar) for my React application. I have tried using react-document-title (seems out of date) and setting document.title in the constructor and componentDidMount() - none of these solutions work.

推荐答案

import React from 'react' import ReactDOM from 'react-dom' class Doc extends React.Component{ componentDidMount(){ document.title = "dfsdfsdfsd" } render(){ return( <b> test </b> ) } } ReactDOM.render( <Doc />, document.getElementById('container') );

这对我有用。

编辑:如果您使用的是webpack-dev-server,则将内联设置为true

If you're using webpack-dev-server set inline to true

更多推荐

如何在React中设置文档标题?

本文发布于:2023-10-09 16:59:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文档   标题   如何在   React

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!