Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt.js [Vue warn]: Unknown custom element: <affix> #15

Closed
ghost opened this issue Mar 27, 2018 · 10 comments
Closed

Nuxt.js [Vue warn]: Unknown custom element: <affix> #15

ghost opened this issue Mar 27, 2018 · 10 comments

Comments

@ghost
Copy link

ghost commented Mar 27, 2018

Sadly can't get the plugin to work in Nuxt.js

Navigation.vue component

    <template>
      <affix class="top-nav" relative-element-selector="#content">
        <nav id="navigation" role="navigation" aria-label="main navigation">
          <a href="#test">Test</a>
        </nav>
      </affix>
    </template

nuxt.config.js

module.exports = {
  plugins: [
    { src: '~/plugins/vue-affix', srr: false }
  ]
}

vue-affix.js

import Vue from 'vue'
var Affix = require('vue-affix');

Vue.use(Affix);
@appinteractive
Copy link

appinteractive commented Apr 7, 2018

You have a typo in ssr (ssr).
And you probably want to wrap the component with <no-ssr></no-ssr>

@ghost
Copy link

ghost commented Apr 9, 2018

Just tried to install the plugin and had a similar problem without nuxt.
Then I changed 'var Affix = require('vue-affix');' to 'import':
import Affix from 'vue-affix';
It sounds silly but it solved my problem.

@eddiemf
Copy link
Owner

eddiemf commented Apr 21, 2018

Have you had any success on getting this to work? I'm not sure if it's because of your typo or if it's really a bug.

Thanks for the feedback!

@appinteractive
Copy link

@eddiemf for me at least it worked like a charm. @lempert, @NetBzz I also used import instead of require. With require you sometimes may have to add .default to the end.

@ghost
Copy link
Author

ghost commented Apr 23, 2018

Yes, using import instead of require worked and I also had to use <no-ssr> tags.

@ghost ghost closed this as completed Apr 23, 2018
@scoutrul
Copy link

Hello! I'm using this plugin with Nuxt too and had same problem.
You should add info about Nuxt installation to the doc.
This is my way:

  1. add Affix plugin to nuxt config
 import Affix from 'vue-affix';
 Vue.use(Affix)
  1. use tag 'affix'

@yvess
Copy link

yvess commented Jun 2, 2020

with nuxt 2.12 I need to do this:

nuxt.config.js

...
  plugins: [
    { src: '~/plugins/vue-affix', mode: 'client' }
  ],
...

plugins/vue-affix.js

import Vue from 'vue'
import Affix from 'vue-affix'

if (process.client) {
  Vue.use(Affix)
}

in template

...
      <client-only>
        <affix
          relative-element-selector="#content"
          style="width: 400px"
        >
        ...
       </affix>
     </client-only>
...

@appinteractive
Copy link

The <client-only/> part might be really bad depending on the content rendered inside as it will not get indexed by search machines properly. The package should account for this and just output the slot content when window is not available.

@yvess
Copy link

yvess commented Jun 2, 2020

The <client-only/> part might be really bad depending on the content rendered inside as it will not get indexed by search machines properly. The package should account for this and just output the slot content when window is not available.

Yes it would be better if the package would properly support SSR

@CavalcanteLeo
Copy link

No plans to support SSR?

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants