Toggle navigation
Toggle navigation
This project
Loading...
Sign in
201side
/
floater
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
3
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
robin*
2020-12-10 11:36:28 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c026b943044b862fe5128d848937afeff9570240
c026b943
1 parent
d0e78ad5
스레드 페이지 제작
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
src/routes/thread.js
src/views/thread.handlebars
src/routes/thread.js
0 → 100644
View file @
c026b94
const
app
=
require
(
'../server'
);
const
db
=
require
(
'../db'
);
app
.
get
(
'/thread/:tid'
,
async
(
req
,
res
)
=>
{
let
thread
=
await
db
.
get
(
'thread'
).
findOne
(
req
.
params
.
tid
);
if
(
!
thread
)
{
res
.
status
(
404
).
send
(
'그런 스레드는 없습니다.'
);
}
res
.
render
(
'thread'
,
{
thread
});
});
\ No newline at end of file
src/views/thread.handlebars
0 → 100644
View file @
c026b94
<style>
.card
{
padding
:
10px
;
margin-bottom
:
10px
;
}
</style>
<section
id=
"app"
style=
"max-width: 600px;margin: 10px auto 0;"
>
<div
class=
"card"
>
<h3
class=
"card-title"
>
{{
thread
.
title
}}
</h3>
<h6
class=
"card-subtitle text-muted"
>
#1
{{
thread
.
writer
}}
{{
dateFromObjectId
thread
.
_id
}}
</h6>
<p
class=
"card-text"
>
{{
thread
.
content
}}
</p>
</div>
<div
class=
"card"
v-for=
"thread in threads"
>
<h6
class=
"card-subtitle text-muted"
>
\{{thread.writer}} \{{dateFromObjectId(thread._id)}}
</h6>
<p
class=
"card-text"
>
\{{thread.content}}
</p>
</div>
<textarea
class=
"form-control"
id=
"input-content"
v-model=
"content"
rows=
"5"
required
></textarea>
<button
class=
"btn btn-primary"
@
click=
"write()"
>
작성
</button>
</section>
<script
src=
"https://unpkg.com/vue@next"
></script>
<script
src=
"/socket.io/socket.io.js"
></script>
<script>
let socket;
let app = {
data() {
return {
threads: [],
content: ''
}
},
methods: {
dateFromObjectId(o) {
o = new Date(parseInt(o.toString().substring(0, 8), 16) * 1000);
return `${o.getFullYear()}-${o.getMonth()}-${o.getDate()} ${o.getHours()}:${o.getMinutes()}`;
},
write() {
socket.emit('write', this.content);
this.content = '';
}
},
created() {
socket = io();
socket.emit('init', '
{{
thread
.
_id
}}
');
socket.on('
thread
', (thread) => {
this.threads.push(thread);
});
}
};
Vue.createApp(app).mount('
#
app
'
);
</script>
\ No newline at end of file
Please
register
or
login
to post a comment