函數(shù)代碼如下class networkEngine{
get(req){
req.type = 'get' ;
req.dataType = 'json' ;
req.cache = 'false' ;
req.beforeSend = xhr =>{
xhr.setRequestHeader('siXtRq3jPQlKpfKa15PFN6cS-gzGzoHsz ','u5SyAXObPG19dqtpnt1NOnoe ') ;
} ;
$.ajax(req) ;
}
tests(){ console.log("test1")
}
}export { networkEngine as default } ;組件中的代碼如下import networkEngine from './../Server/networkEngine' ;class Teamholl extends React.Component {
componentDidMount() {
networkEngine.tests()
}
render(){ return (
<div>...</div>
) ;
}
}
export { Teamholl as default } ;報(bào)錯(cuò)信息如下Uncaught TypeError: _networkEngine2.default.tests is not a function我有幾點(diǎn)疑問(wèn):1,為什么我的類(lèi)名是networkEngine報(bào)錯(cuò)信息卻提示_networkEngine2.default.tests不是函數(shù)。2,正確的調(diào)用方式是什么?3,ajax的get請(qǐng)求,如何傳遞返回值?我是前端初學(xué),希望可以講具體一點(diǎn),謝謝。
在react項(xiàng)目中用es6封裝ajax請(qǐng)求,組件中調(diào)用總是報(bào)錯(cuò),求解?
炎炎設(shè)計(jì)
2018-08-06 09:09:20