Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

250
Vistas
Nuxt2: custom function on Object prototype always fail

In a Nuxt2 project, I want to add a custom function on Object.prototype

~/plugins/extend.js

Object.prototype.only = function(...allows) {
    return Object.keys(this)
        .filter(key => allows.includes(key))
        .reduce((obj, key) => {
            obj[key] = this[key];
            return obj;
        }, {});
}

nuxt.config.js

export default {
    plugins: ['~/plugins/extend.js'],
};

But I will get errors no matter what name I use for the function

 [Vue warn]: The computed property "only" is already defined in data.                                                                                                  

and this only occurs on Object.prototype instead of any other prototype

those work well as expected

~/plugins/extend.js

String.prototype.html2text = function() {
    return this.replace(/ *\<[^>]*\> */g, '');
}

So, how can I use a custom function on Object.prototype without errors in Nuxt2?

Thanks a lot for any reply!

Reproduction

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda