vue数组方法 复制对象


在main.js写

// eslint-disable-next-line no-extend-native
Array.prototype.indexOf = function (val) {
for (let i = 0; i < this.length; i++) {
if (this[i] === val) return i
}
return -1
}
// eslint-disable-next-line no-extend-native
Array.prototype.remove = function (val) {
let index = this.indexOf(val)
if (index > -1) {
this.splice(index, 1)
}
}

复制对象
Vue.prototype.clone = function (obj) {
var copy = (obj instanceof Array) ? [] : {}
for (let attr in obj) {
if (!obj.hasOwnProperty(attr)) continue
copy[attr] = (typeof obj[attr] === 'object') ? this.clone(obj[attr]) : obj[attr]
}
return copy
}

调用
this.clone(obj)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM