Skip to content

Commit a3b1019

Browse files
committed
[Update] Add basic examples
1 parent 5b29239 commit a3b1019

File tree

12 files changed

+176
-43
lines changed

12 files changed

+176
-43
lines changed

assets/css/global.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
h2 {
2+
font-size: 1.25rem;
3+
}
4+
15
* {
2-
font-size: 14px;
6+
font-family: system-ui;
37
}

components/README.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

layouts/default.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
<template>
2-
<div class="Layout">
3-
<main id="main" ref="main" class="Layout__content">
2+
<ElContainer direction="vertical" class="Layout">
3+
<ElHeader height="auto">
4+
<h1>nuxt-netlify-functions-example</h1>
5+
</ElHeader>
6+
<ElMain>
47
<nuxt />
5-
</main>
6-
</div>
8+
</ElMain>
9+
<ElFooter>
10+
Created by <a href="https://github.com/wearelucid" target="_blank">Lucid</a>
11+
</ElFooter>
12+
</ElContainer>
713
</template>
814

915
<style src='./layout.scss' lang='scss' />

layouts/layout.scss

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
@import '../assets/css/global';
2-
3-
$c: 'Layout';
4-
$p: 'Page';
1+
$l: 'Layout';
52

63
/* NUXT default transition */
74
.page-enter-active,
@@ -14,10 +11,7 @@ $p: 'Page';
1411
opacity: 0;
1512
}
1613

17-
.#{$c} {
18-
margin: auto;
19-
}
20-
21-
.#{$p} {
22-
margin: auto;
14+
.#{$l} {
15+
max-width: 600px;
16+
margin: 0 auto;
2317
}

netlify-lambda-src/hello-name.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// eslint-disable-next-line require-await
2+
exports.handler = async (event, context) => {
3+
const name = event.queryStringParameters.name || 'World'
4+
5+
return {
6+
statusCode: 200,
7+
body: `Hello, ${name}`
8+
}
9+
}

netlify-lambda-src/hello-world.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
exports.handler = function(event, context, callback) {
2+
callback(null, {
3+
statusCode: 200,
4+
body: 'Hello, World'
5+
})
6+
}

netlify-lambda-src/hello.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

nuxt.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ module.exports = {
1515
/*
1616
** CSS
1717
*/
18-
css: ['@/assets/css/main.scss'],
18+
css: [
19+
'normalize.css',
20+
'@/assets/css/main.scss',
21+
'element-ui/lib/theme-chalk/index.css'
22+
],
23+
24+
/*
25+
** Plugins
26+
*/
27+
plugins: [{ src: '~/plugins/element-ui.js' }],
1928

2029
/*
2130
** Modules

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"dependencies": {
1515
"@nuxtjs/axios": "^5.3.6",
1616
"@nuxtjs/proxy": "^1.3.1",
17+
"element-ui": "^2.5.4",
18+
"normalize.css": "^8.0.1",
1719
"nuxt": "^2.4.0"
1820
},
1921
"devDependencies": {

pages/index.vue

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,74 @@
22
export default {
33
data() {
44
return {
5-
response: ''
5+
examples: {
6+
helloWorld: {
7+
response: '',
8+
error: null
9+
},
10+
helloName: {
11+
name: '',
12+
response: '',
13+
error: null
14+
}
15+
}
616
}
717
},
8-
mounted() {
9-
this.fetchyFetchy()
10-
},
1118
methods: {
12-
async fetchyFetchy() {
13-
const res = await this.$axios.$get('/.netlify/functions/hello')
14-
this.response = res
19+
async helloWorld() {
20+
try {
21+
const res = await this.$axios.$get('/.netlify/functions/hello-world')
22+
this.examples.helloWorld.response = res
23+
this.examples.helloWorld.error = null
24+
} catch (e) {
25+
this.examples.helloWorld.error = e.response
26+
}
27+
},
28+
async helloName(name) {
29+
try {
30+
const res = await this.$axios.$get(
31+
`/.netlify/functions/hello-name?name=${name}`
32+
)
33+
this.examples.helloName.response = res
34+
this.examples.helloName.error = null
35+
} catch (e) {
36+
this.examples.helloName.error = e.response
37+
}
1538
}
1639
}
1740
}
1841
</script>
1942

2043
<template>
21-
<div class="Page">
22-
Response: {{ response }}
44+
<div>
45+
<hr class="separator">
46+
<h2>Hello, World!</h2>
47+
<ElButton slot="append" type="primary" :loading="false" @click="helloWorld()">Ok cool</ElButton>
48+
<p>Response: {{ examples.helloWorld.response }}</p>
49+
<p v-if="examples.helloWorld.error" style="color:red;"><strong>Error {{ examples.helloWorld.error.status }}</strong><br>{{ examples.helloWorld.error.data }}</p>
50+
<hr class="separator">
51+
<h2>Hello, {name}</h2>
52+
<ElInput v-model="examples.helloName.name" placeholder="Your name">
53+
<ElButton slot="append" type="primary" @click="helloName(examples.helloName.name)">👋 Say hello</ElButton>
54+
</ElInput>
55+
<p>Response: {{ examples.helloName.response }}</p>
56+
<p v-if="examples.helloName.error" style="color:red;"><strong>Error {{ examples.helloName.error.status }}</strong><br>{{ examples.helloName.error.data }}</p>
57+
<hr class="separator">
2358
</div>
2459
</template>
60+
61+
<style lang="scss">
62+
.separator {
63+
margin: 3em 0;
64+
border-color: lightgray;
65+
border-width: 0.5px;
66+
67+
&:first-child {
68+
margin-top: 0;
69+
}
70+
71+
&:last-child {
72+
margin-bottom: 0;
73+
}
74+
}
75+
</style>

plugins/element-ui.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Vue from 'vue'
2+
import Element from 'element-ui'
3+
import locale from 'element-ui/lib/locale/lang/en'
4+
5+
export default () => {
6+
Vue.use(Element, { locale })
7+
}

yarn.lock

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,13 @@ async-limiter@~1.0.0:
14341434
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8"
14351435
integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==
14361436

1437+
async-validator@~1.8.1:
1438+
version "1.8.5"
1439+
resolved "https://registry.yarnpkg.com/async-validator/-/async-validator-1.8.5.tgz#dc3e08ec1fd0dddb67e60842f02c0cd1cec6d7f0"
1440+
integrity sha512-tXBM+1m056MAX0E8TL2iCjg8WvSyXu0Zc8LNtYqrVeyoL3+esHRZ4SieE9fKQyyU09uONjnMEjrNBMqT0mbvmA==
1441+
dependencies:
1442+
babel-runtime "6.x"
1443+
14371444
async@^2.3.0:
14381445
version "2.6.1"
14391446
resolved "https://registry.yarnpkg.com/async/-/async-2.6.1.tgz#b245a23ca71930044ec53fa46aa00a3e87c6a610"
@@ -1500,6 +1507,11 @@ babel-eslint@^10.0.1:
15001507
eslint-scope "3.7.1"
15011508
eslint-visitor-keys "^1.0.0"
15021509

1510+
babel-helper-vue-jsx-merge-props@^2.0.0:
1511+
version "2.0.3"
1512+
resolved "https://registry.yarnpkg.com/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-2.0.3.tgz#22aebd3b33902328e513293a8e4992b384f9f1b6"
1513+
integrity sha512-gsLiKK7Qrb7zYJNgiXKpXblxbV5ffSwR0f5whkPAaBAR4fhi6bwRZxX9wBlIc5M/v8CCkXUbXZL4N/nSE97cqg==
1514+
15031515
babel-loader@^8.0.0, babel-loader@^8.0.5:
15041516
version "8.0.5"
15051517
resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.0.5.tgz#225322d7509c2157655840bba52e46b6c2f2fe33"
@@ -1510,6 +1522,14 @@ babel-loader@^8.0.0, babel-loader@^8.0.5:
15101522
mkdirp "^0.5.1"
15111523
util.promisify "^1.0.0"
15121524

1525+
babel-runtime@6.x:
1526+
version "6.26.0"
1527+
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
1528+
integrity sha1-llxwWGaOgrVde/4E/yM3vItWR/4=
1529+
dependencies:
1530+
core-js "^2.4.0"
1531+
regenerator-runtime "^0.11.0"
1532+
15131533
balanced-match@^1.0.0:
15141534
version "1.0.0"
15151535
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
@@ -2275,7 +2295,7 @@ copy-descriptor@^0.1.0:
22752295
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
22762296
integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=
22772297

2278-
core-js@^2.5.7:
2298+
core-js@^2.4.0, core-js@^2.5.7:
22792299
version "2.6.3"
22802300
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.3.tgz#4b70938bdffdaf64931e66e2db158f0892289c49"
22812301
integrity sha512-l00tmFFZOBHtYhN4Cz7k32VM7vTn3rE2ANjQDxdEN6zmXZ/xq1jQuutnmHvMG1ZJ7xd72+TA5YpUK8wz3rWsfQ==
@@ -2674,6 +2694,11 @@ deep-is@~0.1.3:
26742694
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
26752695
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
26762696

2697+
deepmerge@^1.2.0:
2698+
version "1.5.2"
2699+
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-1.5.2.tgz#10499d868844cdad4fee0842df8c7f6f0c95a753"
2700+
integrity sha512-95k0GDqvBjZavkuvzx/YqVLv/6YYa17fz6ILMSf7neqQITCPbnfEnQvEgMPNjH4kgobe7+WIL0yJEHku+H3qtQ==
2701+
26772702
deepmerge@^3.0.0:
26782703
version "3.1.0"
26792704
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-3.1.0.tgz#a612626ce4803da410d77554bfd80361599c034d"
@@ -2884,6 +2909,18 @@ electron-to-chromium@^1.3.103:
28842909
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.112.tgz#1f40a68ceda6328f95218dffeda0f4f3d5412a2f"
28852910
integrity sha512-FyVLdiRZnLw2WE5ECtveN0JJ7klyiz/HMfKE1/Rjff3l7pe4vfkYtBlcCqTckvR8E7asjJGh0m9gRPR3Anp/UA==
28862911

2912+
element-ui@^2.5.4:
2913+
version "2.5.4"
2914+
resolved "https://registry.yarnpkg.com/element-ui/-/element-ui-2.5.4.tgz#1e051032026a144bc18f7920f0be927977541cb8"
2915+
integrity sha512-VlyPZ1A2VtVJdnu9nUV+u/eGhKaEF+IoENbDgNlUza0Slj6Jb0bC9mzK95JK2g7QSe8YXUWhQVy+d2kZUE2oKQ==
2916+
dependencies:
2917+
async-validator "~1.8.1"
2918+
babel-helper-vue-jsx-merge-props "^2.0.0"
2919+
deepmerge "^1.2.0"
2920+
normalize-wheel "^1.0.1"
2921+
resize-observer-polyfill "^1.5.0"
2922+
throttle-debounce "^1.0.1"
2923+
28872924
elliptic@^6.0.0:
28882925
version "6.4.1"
28892926
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.4.1.tgz#c2d0b7776911b86722c632c3c06c60f2f819939a"
@@ -5638,6 +5675,16 @@ normalize-url@^4.1.0:
56385675
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-4.1.0.tgz#307e74c87473efa81969ad1b4bb91f1990178904"
56395676
integrity sha512-X781mkWeK6PDMAZJfGn/wnwil4dV6pIdF9euiNqtA89uJvZuNDJO2YyJxiwpPhTQcF5pYUU1v+kcOxzYV6rZlA==
56405677

5678+
normalize-wheel@^1.0.1:
5679+
version "1.0.1"
5680+
resolved "https://registry.yarnpkg.com/normalize-wheel/-/normalize-wheel-1.0.1.tgz#aec886affdb045070d856447df62ecf86146ec45"
5681+
integrity sha1-rsiGr/2wRQcNhWRH32Ls+GFG7EU=
5682+
5683+
normalize.css@^8.0.1:
5684+
version "8.0.1"
5685+
resolved "https://registry.yarnpkg.com/normalize.css/-/normalize.css-8.0.1.tgz#9b98a208738b9cc2634caacbc42d131c97487bf3"
5686+
integrity sha512-qizSNPO93t1YUuUhP22btGOo3chcvDFqFaj2TRybP0DMxkHOCTYwp3n34fel4a31ORXy4m1Xq0Gyqpb5m33qIg==
5687+
56415688
npm-bundled@^1.0.1:
56425689
version "1.0.5"
56435690
resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.0.5.tgz#3c1732b7ba936b3a10325aef616467c0ccbcc979"
@@ -7042,6 +7089,11 @@ regenerate@^1.2.1, regenerate@^1.4.0:
70427089
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"
70437090
integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg==
70447091

7092+
regenerator-runtime@^0.11.0:
7093+
version "0.11.1"
7094+
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9"
7095+
integrity sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==
7096+
70457097
regenerator-runtime@^0.12.0:
70467098
version "0.12.1"
70477099
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz#fa1a71544764c036f8c49b13a08b2594c9f8a0de"
@@ -7213,6 +7265,11 @@ requires-port@^1.0.0:
72137265
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
72147266
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
72157267

7268+
resize-observer-polyfill@^1.5.0:
7269+
version "1.5.1"
7270+
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
7271+
integrity sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg==
7272+
72167273
resolve-from@^1.0.0:
72177274
version "1.0.1"
72187275
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"
@@ -8070,6 +8127,11 @@ thread-loader@^1.2.0:
80708127
loader-runner "^2.3.0"
80718128
loader-utils "^1.1.0"
80728129

8130+
throttle-debounce@^1.0.1:
8131+
version "1.1.0"
8132+
resolved "https://registry.yarnpkg.com/throttle-debounce/-/throttle-debounce-1.1.0.tgz#51853da37be68a155cb6e827b3514a3c422e89cd"
8133+
integrity sha512-XH8UiPCQcWNuk2LYePibW/4qL97+ZQ1AN3FNXwZRBNPPowo/NRU5fAlDCSNBJIYCKbioZfuYtMhG4quqoJhVzg==
8134+
80738135
through2@^2.0.0:
80748136
version "2.0.5"
80758137
resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.5.tgz#01c1e39eb31d07cb7d03a96a70823260b23132cd"

0 commit comments

Comments
 (0)