-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7ce54ec
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const app = { | ||
data() { | ||
return { | ||
title: "VTwitter", | ||
item: "", | ||
items: [ | ||
{ | ||
id: 1, | ||
body: "hello vue 3", | ||
avatar: `https://avatars.dicebear.com/api/male/1.svg`, | ||
date: new Date(Date.now()).toLocaleString(), | ||
}, | ||
{ | ||
id: 2, | ||
body: "hello world", | ||
avatar: `https://avatars.dicebear.com/api/male/2.svg`, | ||
date: new Date(Date.now()).toLocaleString(), | ||
}, | ||
], | ||
}; | ||
}, | ||
methods: { | ||
onSubmit() { | ||
this.items.push({ | ||
id: Math.round(Math.random() * 30), | ||
avatar: `https://avatars.dicebear.com/api/male/${Date.now()}.svg`, | ||
body: this.item, | ||
date: new Date(Date.now()).toLocaleString(), | ||
}); | ||
|
||
// reset | ||
this.item = ""; | ||
}, | ||
}, | ||
}; | ||
|
||
Vue.createApp(app).mount("#app"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vue.js App</title> | ||
<script src="https://unpkg.com/vue@next"></script> | ||
</head> | ||
<body> | ||
<div id="app"> | ||
<h1>{{title}}</h1> | ||
|
||
<form @submit.prevent="onSubmit"> | ||
<textarea | ||
v-model="item" | ||
required | ||
placeholder="Type tweet here" | ||
></textarea> | ||
<br /> | ||
<button type="submit">Submit</button> | ||
</form> | ||
<ul> | ||
<li v-for="tweet in items" key="tweet.id"> | ||
<img style="width: 30px; height: 30px" :src="tweet.avatar" /> | ||
<span>{{tweet.date}}</span> | ||
<div>{{tweet.body}}</div> | ||
</li> | ||
</ul> | ||
</div> | ||
<script src="./app.js"></script> | ||
</body> | ||
</html> |