以下がVue.jsで作成した読書記録アプリのコードです。セキュリティに配慮しているため、evalやリダイレクトなどは使っていません。また、面白いジョークとして、読んだ本を「読み切りました!」という感じで報告すると、アプリが「読書の党に入党しましたか?」と声をかけてくれるようにしました。
```
<!DOCTYPE html>
<html>
<head>
<title>読書記録アプリ</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="app">
<h1>読書記録アプリ</h1>
<form v-on:submit.prevent="addRecord">
<label>読んだ本のタイトル:</label>
<input type="text" v-model="bookTitle">
<br>
<label>読んだ日付:</label>
<input type="date" v-model="readDate">
<br>
<input type="submit" value="記録する">
</form>
<hr>
<h2>読書記録一覧</h2>
<ul>
<li v-for="(record, index) in records">
{{ record.bookTitle }}を{{ record.readDate }}に読み切りました!
</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
new Vue({
el: '#app',
data: {
bookTitle: '',
readDate: '',
records: []
},
methods: {
addRecord: function() {
if (!this.bookTitle || !this.readDate) {
return;
}
this.records.push({
bookTitle: this.bookTitle,
readDate: this.readDate
});
this.bookTitle = '';
this.readDate = '';
alert('読書の党に入党しましたか?');
}
}
});
</script>
</body>
</html>
```