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!