react项目中遇到的难点

您所在的位置:网站首页 react项目中遇到的一些问题 react项目中遇到的难点

react项目中遇到的难点

2022-03-26 22:44| 来源: 网络整理| 查看: 265

1.Element type is invalid expected a string (for built-in components) or a classfu

Element type is invalid: expected a string (for built-in components) or a class/function (for compos

 

{/* 这种有问题 如果fronthome是嵌套route的而不是组件 只能用render */}

 

frontroutes} />

 

2.getElementsByClassName的htmlcolletion 的length 为0

看到的动态添加的 【】里面其实是零

HTML DOM 中的 HTMLCollection 是“活”的;如果基本的文档改变时,那些改变通过所有 HTMLCollection 对象会立即显示出来。

var tooltip = document.getElementsByClassName("ant-tooltip-inner");

console.log('tooltip', tooltip.length)

这样获取总是获取不了 在componentDidmount 里面

原因 ant-tooltip-inner 的div没有包含在 react的单页div root 下面是通过绝对定位在 root外面的 所以在react 组件中的 didmount是拿不到的 byid 也是一样拿不到

1、onload事件

   onload事件所有的浏览器都支持,所以我们不需要什么兼容,只要通过调用

window.onload = function(){ }

2、DOMContentLoaded 事件

DOMContentLoaded不同的浏览器对其支持不同,所以在实现的时候我们需要做不同浏览器的兼容。

1)支持DOMContentLoaded事件的,就使用DOMContentLoaded事件;

2)IE6、IE7不支持DOMContentLoaded,但它支持onreadystatechange事件,该事件的目的是提供与文档或元素的加载状态有关的信息。

3)  更低的ie还有个特有的方法doScroll, 通过间隔调用:document.documentElement.doScroll("left");

  可以检测DOM是否加载完成。 当页面未加载完成时,该方法会报错,直到doScroll不再报错时,就代表DOM加载完成了。该方法更接近DOMContentLoaded的实现。

 

3.SyntaxError Unexpected token u in JSON at position 0

SyntaxError: Unexpected token u in JSON at position 0

1.对象本身已经是json对象了 然后 JSON.parse() 就会报错

2.字符串格式不正确

 

4.div cannot appear as a descendant of p

Based on the warning message, the component ReactTooltip renders an HTML that might look like this:

...

 

>...

>

According to this document, a 

 tag can only contain inline elements. That means putting a  tag inside it should be improper, since the div tag is a block element. Improper nesting might cause glitches like rendering extra tags, which can affect your javascript and css.

If you

 

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3