|
| 1 | +<template> |
| 2 | + <section class="container"> |
| 3 | + <div class="row mt-3 mb-5"> |
| 4 | + <div class="col-lg-12"> |
| 5 | + <h2 class="mb-0">Hello World Lambda</h2> |
| 6 | + <p class="text-muted"> |
| 7 | + A very simple lambda function that returns some text |
| 8 | + </p> |
| 9 | + </div> |
| 10 | + |
| 11 | + <b-col lg="12"> |
| 12 | + <div class="card card-body bg-dark text-light"> |
| 13 | + <b-row> |
| 14 | + <b-col v-if="loading" lg="12" class="text-center"> |
| 15 | + <font-awesome-icon size="4x" icon="spinner" spin /> |
| 16 | + </b-col> |
| 17 | + <b-col v-else lg="12"> |
| 18 | + <p>Response from Lambda: {{ response }}</p> |
| 19 | + <p v-if="error"> |
| 20 | + <strong>Error {{ error.status }}</strong> |
| 21 | + <br /> |
| 22 | + {{ error.data }} |
| 23 | + </p> |
| 24 | + </b-col> |
| 25 | + </b-row> |
| 26 | + </div> |
| 27 | + </b-col> |
| 28 | + </div> |
| 29 | + </section> |
| 30 | +</template> |
| 31 | + |
| 32 | +<script> |
| 33 | +export default { |
| 34 | + head() { |
| 35 | + return { |
| 36 | + title: 'Nuxt Netlify Lambda - Hello World', |
| 37 | + meta: [ |
| 38 | + { |
| 39 | + hid: 'description', |
| 40 | + name: 'description', |
| 41 | + content: 'Nuxt Netlify Lambda - Hello World Description' |
| 42 | + } |
| 43 | + ] |
| 44 | + } |
| 45 | + }, |
| 46 | + data() { |
| 47 | + return { |
| 48 | + response: '', |
| 49 | + error: null, |
| 50 | + loading: false |
| 51 | + } |
| 52 | + }, |
| 53 | + created() { |
| 54 | + this.invokeLambda() |
| 55 | + }, |
| 56 | + methods: { |
| 57 | + async invokeLambda() { |
| 58 | + this.loading = true |
| 59 | + try { |
| 60 | + const res = await this.$axios.$get('/.netlify/functions/hello') |
| 61 | + this.response = res |
| 62 | + this.error = null |
| 63 | + this.loading = false |
| 64 | + } catch (e) { |
| 65 | + this.error = e.response |
| 66 | + this.response = '—' |
| 67 | + this.loading = false |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | +</script> |
0 commit comments