Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
Nuxt2: la función personalizada en el prototipo de objeto siempre falla

En un proyecto Nuxt2, quiero agregar una función personalizada en Object.prototype

~/plugins/extender.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'], };

Pero obtendré errores sin importar el nombre que use para la función.

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

y esto solo ocurre en Object.prototype en lugar de cualquier otro prototype

esos funcionan bien como se esperaba

~/plugins/extender.js

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

Entonces, ¿cómo puedo usar una función personalizada en Object.prototype sin errores en Nuxt2?

¡Muchas gracias por cualquier respuesta!

Reproducción

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!