我刚开始学习反应。没有类(函数式编程)可以做到这一点吗?Index.js 有一个带有 axios 调用的按钮。当答案到来时,通知应该会出现并在一秒钟内消失。
应用程序.js
import React from 'react';
import {BrowserRouter, Route} from 'react-router-dom';
import Index from './components/index/index';
import Notifications from './components/notifications/notifications';
const App = (props) => {
return (
<BrowserRouter>
<Route exact path="/" render={ () => <Index notification={ <Notifications/> } /> } />
</BrowserRouter>
);
}
export default App;
索引.js
import React from 'react';
const axios = require('axios');
const Index = (props) => {
let getData = () => {
axios.get('url')
.then(function (response) {
<Notification text={ response.data }/> );
})
.catch(function (error) {
console.log(error);
});
}
return (
<button onClick={ () => getData() }>Get data</button>
);
}
export default Index;
通知.js
import React from 'react';
const Notification = (props) => {
return (
<div>
<div>
<p>props.text</p>
</div>
</div>
);
//and delete after 1 second
}
export default Notification;
请显示功能解决方案的示例:)
桃花长相依
开满天机
HUWWW
相关分类