Skip to content

Instantly share code, notes, and snippets.

@karl-gustav
Created May 16, 2018 15:04
Show Gist options
  • Save karl-gustav/d160138b0036d4c561d5f8aba27eea62 to your computer and use it in GitHub Desktop.
Save karl-gustav/d160138b0036d4c561d5f8aba27eea62 to your computer and use it in GitHub Desktop.
An hello world with vue + fetch
<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