How to call "mounted" in ssr

  • According to the docs:

    Since there are no dynamic updates, of all the Vue lifecycle hooks, only beforeCreate and created will be called during SSR. This means any code inside other lifecycle hooks such as beforeMount or mounted will only be executed on the client.

    I’m confused at how to make this call happen. I have some stuff that can’t run on the server. I would have guessed that having “mounted” alone would cause it to fire, but that doesn’t seem to happen.

    To add a little context, I’m building a drop-down menu using foundation. I have it working on standard Vue (non-ssr).

    The file looks like this:

    <ul class="vertical menu accordion-menu" data-accordion-menu data-multi-open="false">
        <li v-for="i in htmlData.sidenav" :key="i.title">
            <router-link v-bind:to=i.href>{{ i.title }}</router-link>
            <ul class="menu vertical nested" v-if="i.sub1">
                <li v-for="j in i.sub1" :key="">
                    <router-link v-bind:to=j.href>{{ }}</router-link>
                    <ul class="menu vertical nested" v-if="j.sub2">
                        <li v-for="k in j.sub2" :key="">
                            <router-link v-bind:to=k.href>{{ }}</router-link>
    import SideNav from '../store/modules/sidenav'
    import $ from 'jquery'
    export default {
        name: 'sidenav',
        computed: {
            htmlData () {
                return this.$
        // Server-side only
        serverPrefetch () {
            this.$store.registerModule('sn',  SideNav)
            return this.getData()
        // Client-side only
        mounted () {
            const doesExist = !!this.$
            this.$store.registerModule('sn', SideNav, { preserveState: true })
            if (!doesExist) {
        destroyed () {
        methods: {
            async getData () {
                return this.$store.dispatch('sn/snav')
            acc () {
                this.$nextTick(function () {
           = new this.$foundation.AccordionMenu($('.accordion-menu'))

    While the sidenav does render, the client is unable to see it, which results in this error:

    UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'AccordionMenu' of undefined

    This is wrong because the menu does render, there is no log of mt in console, although pref does log. This causes a slew of other problems with page rendering (it doesn’t without hard refresh).

    The file under boot/sidenav looks like this:

    // const SideNav = () => import('../layouts/SideNav.vue')
    import SideNav from '../layouts/SideNav.vue'
    export default async ({ Vue }) => {
        Vue.component('side-nav', SideNav)

    And the quasar.conf has this:

            boot: [
                    path: 'foundation',
                    server: false
                    path: 'osmd',
                    server: false

    The client can’t see either foundation or osmd. Neither can run on the server since they both require window to run. It’s doubly confusing because sidenav does render and behave like a reactive component.

Log in to reply