Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@webloglife
Last active February 25, 2018 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webloglife/abb2f09e2dff2b00399ba8c67d4bef7b to your computer and use it in GitHub Desktop.
Save webloglife/abb2f09e2dff2b00399ba8c67d4bef7b to your computer and use it in GitHub Desktop.
<ul id="app">
<li v-for="(item,index) in items">
<img v-bind:src="item.snippet.thumbnails.high.url">
<span class="title">{{ item.snippet.title }}</span>
</li>
</ul>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
axios.get('https://www.googleapis.com/youtube/v3/playlistItems',{
params: {
part: 'snippet',
playlistId: 'PL55713C70BA91BD6E',/*プレイリストのID*/
maxResults: 6, /*表示する件数*/
key: 'APIキー' /*Youtube Data API で使う認証キー*/
}
}).then((response) => {
Init(response.data.items);
}).catch( error => { console.log(error); });
function Init(data){
new Vue({
el: '#app',
data: {
items:[]
},
created: function(){
for(var i = 0; i < data.length; i++){
this.items.push(data[i]);
}
},
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment