Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
Javascript how to use imported object in function?

UPDATED ...

I'm trying to use imported object in my nuxt.config.js This is Nuxt.js configuration file.

I have this: seo.js

export default {
  link: [
    {
      rel: 'icon',
      type: 'image/x-icon',
      href: '/img/favicon.ico',
    },
  ],
  meta: [
    { 
      charset: 'utf-8' 
    }
  ]
}

Then in nuxt.config.js:

import seo from './seo'

export default {
  head() {
    return {
        ...seo,
    }
  },
  ... other config setting ...
}

Then I'm getting an error: "_seo is not defined" I'm not trying to export head as function, this is config file and there are more settings.

While this works, nuxt.config.js:

import seo from './seo'

export default {
  head: {
        ...seo,
    }
  }
  ... other config settings ...
}

It seams that I can't use imported object in function. I'm confused, what is the problem here and how can I use that imported object?

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Change you nuxt.config.js to the following

import seo from "./seo";

export const head = () => {
  return {
    ...seo
  };
};

export default head;

I have put this on a code sandbox, if you look at the console log it is outputting the correct information

https://codesandbox.io/s/vigilant-almeida-j8dyq?file=/src/App.js

about 4 years ago · Santiago Trujillo Relatório

0

Instead of exporting head as a method of the default object, you can directly default export the function

import seo from "./seo";

export default function() {
  return {
    ...seo
  };
};
about 4 years ago · Santiago Trujillo Relatório

0

for such exports, it is recommended to use the named export.

export const links = [
{
  rel: 'icon',
  type: 'image/x-icon',
  href: '/img/favicon.ico',
},

]

And Import it as follow:

import {seo} from './seo'
export default {
   head: {
    ...seo,
  }

} }

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda