Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김지훈
/
3line
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
2
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김지훈
2016-11-12 22:41:38 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ea40909b570e1c707c4f9b4cfc6fa8a589e77f62
ea40909b
1 parent
74a498a9
Add : fetch shorten sentences from the server
I used axios for ajax.
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
4 deletions
Client/package.json
Client/src/App.js
Client/package.json
View file @
ea40909
...
...
@@ -6,6 +6,7 @@
"react-scripts"
:
"0.6.1"
},
"dependencies"
:
{
"axios"
:
"^0.15.2"
,
"react"
:
"^15.3.2"
,
"react-dom"
:
"^15.3.2"
},
...
...
Client/src/App.js
View file @
ea40909
import
React
,
{
Component
}
from
'react'
;
import
logo
from
'./logo.png'
;
import
'./App.css'
;
import
axios
from
'axios'
;
class
App
extends
Component
{
constructor
(
props
){
super
(
props
);
this
.
state
=
{
shorten
:
[]
};
this
.
fetchShorten
=
this
.
fetchShorten
.
bind
(
this
);
this
.
printShorten
=
this
.
printShorten
.
bind
(
this
);
}
componentDidMount
(){
this
.
fetchShorten
();
}
fetchShorten
()
{
var
URL
=
'http://localhost:4000'
;
return
axios
.
get
(
URL
)
.
then
((
response
)
=>
{
console
.
log
(
response
);
this
.
setState
({
shorten
:
response
.
data
.
shorten
});
})
.
catch
((
error
)
=>
{
this
.
setState
({
shorten
:
error
});
});
}
printShorten
()
{
if
(
this
.
state
.
shorten
){
return
(
<
div
>
<
p
>
1
:
{
this
.
state
.
shorten
[
0
]}
<
/p
>
<
p
>
2
:
{
this
.
state
.
shorten
[
1
]}
<
/p
>
<
p
>
3
:
{
this
.
state
.
shorten
[
2
]}
<
/p
>
<
/div
>
);
}
}
render
()
{
return
(
<
div
className
=
"App"
>
<
div
className
=
"App-header"
>
<
img
src
=
{
logo
}
className
=
"App-logo"
alt
=
"logo"
/>
<
h2
>
Welcome
to
3
Line
<
/h2
>
<
h2
>
Redesigned
by
3
Line
<
/h2
>
<
/div
>
<
div
className
=
"App-intro"
>
{
this
.
printShorten
()}
<
/div
>
<
p
className
=
"App-intro"
>
Calculating
...
<
/p
>
<
/div
>
);
}
...
...
Please
register
or
login
to post a comment