Last active
May 30, 2018 18:30
-
-
Save graciano/d55cb9a92bbcd64f98e99d9e124be312 to your computer and use it in GitHub Desktop.
js util functions
This file contains hidden or 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
import axios from 'axios' | |
export default async function (path, defaultResult) { | |
try { | |
const response = await axios.get(path) | |
return response.data | |
} catch (err) { | |
console.log(path, defaultResult, err) | |
} | |
return defaultResult || {} | |
} |
This file contains hidden or 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
export default function (destination, source) { | |
Object.entries(source).forEach(entry => { | |
const [key, value] = entry | |
destination[key] = value | |
}) | |
} |
This file contains hidden or 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
<template> | |
<section> | |
<h1>{{title}}</h1> | |
<ul> | |
<li v-for="elem in list" :key="elem.id"> | |
{{ elem.name }} | |
</li> | |
</section> | |
</template> | |
<script> | |
import apiLoadAsync from './apiLoadAsync' | |
import objEntriesCopy from './objEntriesCopy' | |
const pathToContent = id => process.env.CONTENT_ENDPOINT + id | |
const loadContent = async id => apiLoadAsync(pathToContent(id)) | |
export default { | |
name: 'TheContent', | |
data () { | |
return { | |
title: 'Loading Content..', | |
list: [] | |
} | |
} | |
async mounted () { | |
const content = await loadContent(this.$route.params.id) | |
objEntriesCopy(this, content) | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment