Javascript 分析错误:意外标记,应为“quot;”&引用;每当我添加构造函数时?
每当我尝试添加类构造函数时,它都会显示此错误,意外标记,预期“ 我试图使用构造函数初始化内部组件状态,但一直给出此错误。我试过重写代码,但没有成功 没有构造器,一切都很好,请问我错过了什么 我上周才开始学习如何反应Javascript 分析错误:意外标记,应为“quot;”&引用;每当我添加构造函数时?,javascript,reactjs,constructor,react-component,react-state,Javascript,Reactjs,Constructor,React Component,React State,每当我尝试添加类构造函数时,它都会显示此错误,意外标记,预期“ 我试图使用构造函数初始化内部组件状态,但一直给出此错误。我试过重写代码,但没有成功 没有构造器,一切都很好,请问我错过了什么 我上周才开始学习如何反应 import React,{Component}来自'React'; 导入“/App.css”; 函数App(){ 建造师(道具){ 超级(道具); 此.state={ 列表 github }; } 常数列表=[ { 标题:“反应”, 网址:'https://facebook.gi
import React,{Component}来自'React';
导入“/App.css”;
函数App(){
建造师(道具){
超级(道具);
此.state={
列表
github
};
}
常数列表=[
{
标题:“反应”,
网址:'https://facebook.github.io/react/',
作者:《乔丹·沃克》,
num_评论:3,
要点:4,
对象ID:0,
},
{
标题:“Redux”,
网址:'https://github.com/reactjs/redux',
作者:“丹·阿布拉莫夫,安德鲁·克拉克”,
num_评论:2,
要点:五,,
目标1,,
},
];
常量github=[
{
id:1,
名称:“Sanusi Hayatu”,
用户名:“hamicch”,
网址:'https://github.com/hamicch',
回购协议:24
},
{
id:2,
姓名:“Hayatu Michael”,
用户名:“Azez”,
网址:'https://github.com/azeez',
回购协议:30
},
{
id:3,
姓名:“Ridwan Abdulahi”,
用户名:'ridwan',
网址:'https://github.com/ridwan',
回购:50
}
];
返回(
{list.map(项=>
:
{item.author}--
{item.num_comments}--
{item.points}
)}
GitHub帐户
{github.map(用户=>
用户名:
名称:{user.Name}
回购协议:
{user.repos}
)}
);
}
导出默认应用程序;
这是错误页在函数组件中不能有构造函数,它仅为类组件保留。属性的缩写:函数只能在对象文本或类中使用 不能在需要表达式或语句的地方使用它
class-Foo{
构造函数(){
this.ran=Math.random();
}
}
const foo=新foo();
常数条=新的Foo();
console.log(foo.ran);
console.log(bar.ran)代码>谢谢,我将把它改为类组件,看看它是否有效