Created
October 24, 2019 20:22
-
-
Save sroehrl/7cd08662671f962008910eb5e863a3e7 to your computer and use it in GitHub Desktop.
blua.blue in nuxt (poc)
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 is in pages/blog/ | |
<template> | |
<div> | |
<div class="container" v-if="display==='overview'"> | |
<div v-for="post in result"> | |
<a :href="'/blog/'+post.slug">{{post.name}}</a> | |
</div> | |
</div> | |
<div class="container" v-if="display==='post'"> | |
<h1 class="title">{{result.name}}</h1> | |
<div class="content" v-for="content in result.content" v-html="content.content"> | |
</div> | |
</div> | |
</div> | |
</template> | |
<script> | |
import axios from 'axios'; | |
let author = 'yourUserNameFromBluaBlue'; | |
let token = 'Your.JWT.tokenFromBlua.blue' | |
let config = { | |
baseURL: '{{base}}api.v1/', | |
timeout: 8000, | |
headers: { | |
'X-Custom-Header': 'foobar', | |
'Authorization': `Baerer ${token}` | |
} | |
}; | |
const api = axios.create(config); | |
export default { | |
asyncData({params}){ | |
// not specific? | |
let display = typeof params.post !== 'undefined' ? 'post' : 'overview'; | |
let call = display === 'overview' ? `https://blua.blue/api.v1/articleList?author=${author}` : `https://blua.blue/api.v1/article?slug=${params.post}`; | |
return api.get(call) | |
.then((res) => { | |
return { | |
result: res.data, | |
display: display | |
} | |
}) | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment