Created
May 16, 2018 15:04
-
-
Save karl-gustav/d160138b0036d4c561d5f8aba27eea62 to your computer and use it in GitHub Desktop.
An hello world with vue + fetch
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
<html> | |
<head></head> | |
<body> | |
<section id="app"> | |
<p>{{message}}</p> | |
<input v-model="message"> | |
</section> | |
<script src="https://unpkg.com/vue"></script> | |
<script> | |
new Vue({ | |
el: '#app', | |
data: { | |
message: 'Hello Vue.js!', | |
errors: [] | |
}, | |
created() { | |
this.fetchData() | |
}, | |
methods: { | |
fetchData() { | |
fetch('https://jsonplaceholder.typicode.com/posts/1') | |
.then(response => response.json()) | |
.then(data => this.message = data.body) | |
.catch(err => this.errors.push(err)) | |
} | |
} | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment