3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vue.js でリストを読み込む

Last updated at Posted at 2016-11-09

Spring Boot + Doma2 で作ったapiを Vue.js から呼び出し、リストを構築してみた。
今まではjQueryのajaxを利用してapiのデータを受け取っていたが、今回はvue-resourceというものを利用してみた。

pickup.html
<table id="pickup" class="table table-bordered">
	<thead>
		<tr>
			<th></th>
			<th>タイトル</th>
			<th>開始日</th>
		</tr>
	</thead>
	<tbody>
		<tr v-for="item in items">
			<td><img src="{{ item.image }}" width="100" /></td>
			<td>{{ item.title }}</td>
			<td>{{ item.period}}</td>
		</tr>
	</tbody>
</table>
<a href="javascript:append();">append</a>
<script type="text/javascript" th:inline="javascript">/*<![CDATA[*/
	var list = [];
	new Vue({
		el: '#pickup',
		data: {
			items: list
		}
	})
	function append() {
		Vue.http.get('/api/pickup?offset=' + list.length).then((response) => {
			for (i = 0; i < response.body.length; i++) {
				list.push(response.body[i]);
			}
		});
	}
	append();
/*]]>*/</script>

今回は Thymeleaf を利用しているので、

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?