Nuxt.js Setup
Edit nuxt.config.js
to allow functions to access emulator.
export default { modules: [ '@nuxtjs/firebase', ], firebase: { config: { ... }, services: { functions: { location: 'us-central1', emulatorHost: 'http://localhost', emulatorPort: 5001, } } }}
Call the firebase cloud function.
<script>export default { methods: { async callHello() { const hello = this.$fire.functions.httpsCallable('hello'); const result = await hello({name: 'Desmond'}) console.log(result.data) } }, mounted() { callHello() }}</script>
Firebase Cloud Functions
Setup Firebase Project with Functions.
Edit functions/index.js
const functions = require('firebase-functions');exports.hello = functions.https.onRequest(async (request, response) => { const name = request.query.name; response.send(`Hello ${name}`)})
Test
In firebase project, start emulator.
firebase emulator:start
In nuxt project, start dev.
npm run dev