如何在Quasar中添加自定义属性?

阿里·哈拉吉(Ali Hallaji)

我想在Quasar框架中添加自定义属性,但是当我设置它时,ESlint向我显示此错误: Array prototype is read only, properties should not be added

我想为数组添加扩展方法:

Array.prototype.extend = function (other_array) {
    /* You should include a test to check whether other_array really is an array */
    other_array.forEach(function(v) {this.push(v)}, this)
}
查理

扩展对象时,将更改其行为。

更改仅由您自己的代码使用的对象的行为就可以了。但是,当您更改其他代码也使用的某些行为时,就有可能破坏该其他代码。

您可以在此处选择创建一个函数并将其导入:

helpers.js

let extend = function(other_array) {
  return other_array.forEach(function(v) {this.push(v)}, this)
}

export default extend;

componentA.vue

import extend from './helpers.js';

// use extend as a normal function

或者我们可以更聪明一些,并使用Javascript已经拥有的本机方法:

// will 'glue' two arrays together
firstArray.concat(secondArray);

// or using new ECMA syntax (spread operator)
finalArray = [...firstArray, ...secondArray];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在cloudformation中添加自定义属性?

如何在Kylo中添加自定义类别属性?

如何在JSX中添加自定义html属性

如何在Polymer中的自定义元素属性中添加事件侦听器?

如何在Smack 4.1中的XMPP消息标记中添加自定义属性(昵称)

如何在Qt C ++中向自定义控件添加属性?

如何在Codable结构中添加自定义瞬态属性

如何在magento的前端中显示自定义添加的属性列的值

如何在SQL连接字符串中添加自定义属性?

Rails:如何在collection_select中添加自定义数据属性

如何在magento2中向运输方法添加自定义属性

如何在 VueJS/Gridsome 中向页面添加自定义属性

如何在react-bootstrap组件中添加自定义data- *属性

如何在PowerShell中向自定义对象动态添加新属性

Powershell-如何在自定义对象的属性中添加多个对象?

如何在Magento中向地址添加自定义属性?

如何在自定义htmlhelper中添加“类”的默认属性值?

如何在 html 中自定义 onmouseover 属性?

如何在自定义指令中获取评估的属性

如何在自定义组件中评估FacesComponent属性

如何在JAXB中自定义属性名称?

如何在ProdctData JSON中填充自定义属性?

如何在C#中创建自定义属性

如何在Azure中自定义用户属性的类型?

如何在自定义WebViewPage中设置属性?

如何在自定义HttpMessageHandler中设置属性?

如何在Typescript中打印自定义对象的属性?

如何在Javers中自定义属性名称

如何在AutoMapper中添加自定义逻辑?