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

251
Views
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
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!