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
EC2 Default User
committed
Jul 28, 2019
1 parent
f353aeb
commit bbbe8d1
Showing
4 changed files
with
50 additions
and
6 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,18 @@ | ||
//商品のリスト | ||
const database = [ | ||
{id:1, name:'商品A', price:345, content:'商品Aの紹介です'}, | ||
{id:2, name:'商品B', price:9876, content:'商品Bの紹介です'}, | ||
{id:3, name:'商品C', price:123, content:'商品Cの紹介です'}, | ||
] | ||
//インポート先で使用できる関数をオブジェクトとしてまとめたもの | ||
export default { | ||
// databaseを取得 | ||
fetch(id) { return database }, | ||
// idパラメーターに従ってdatabaseからdataを抽出 | ||
find(id) { return database.find(el => el.id === id) }, | ||
anyncFind(id, callback) { | ||
setTimeout(() => { | ||
callback(database.find(el => el.id === id)) | ||
}, 1000) | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,5 +1,21 @@ | ||
<template> | ||
<div class="product"> | ||
<div class="product-list"> | ||
<h1>商品一覧</h1> | ||
<ul> | ||
<!--受け取ったdatabaseをv-forでリストレンダリング--> | ||
<li v-for="{id,name} in list" :key="id"> | ||
<router-link :to="`/product/${ id }`">{{ name }}</router-link> | ||
</li> | ||
</ul> | ||
</div> | ||
</template> | ||
</template> | ||
|
||
<script> | ||
import products from '@/api/products.js' | ||
export default { | ||
computed: { | ||
// products.jsから引き受けたdatabaseをlistという変数にして受け取る | ||
list: () => products.fetch() | ||
} | ||
} | ||
</script> |