N
N
nurdus2018-02-25 21:52:29
Vue.js
nurdus, 2018-02-25 21:52:29

How to correctly implement a dynamic navbar at the layout level in nuxt?

Good evening.
How to correctly implement a dynamic navbar (loaded from the database) at the layout level in nuxt? Now done like this (layouts/default.vue). To what extent is this correct?

<template>
  <div>
    <Menu :menuitems = "menuitems" />
    <nuxt/>
  </div>
</template>

<script>
import Menu from '~/components/Menu.vue'
import api from '~/lib/api.js'
export default {
  data: function() {
    return {
      menuitems: []
    }
  },
  created: async function() {
    let a = await api.menu('top')
    this.$set(this, 'menuitems', a.menuitems)
  },
  components: {
    Menu
  }
}
</script>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question