uniapp使用push在数组的末尾新增元素
push在数组的末尾增加一个元素,一次可以增加多个。
var _self;
export default {
data() {
return {
List:["1"]
}
},
onLoad() {
_self = this;
console.log(this.List);
},
onShow() {
const arr = "2";
_self.List.push(arr);
console.log(this.List);
for(var i=0; i<=5; i++){
const b = ""+i+"";
_self.List.push(b);
}
console.log(this.List);
},
methods: {
}
}
结果:
[“1”, ob: Observer]
(2) [“1”, “2”, ob: Observer]
(8) [“1”, “2”, “0”, “1”, “2”, “3”, “4”, “5”, ob: Observer]
标签:uniapp,Observer,List,self,新增,ob,push From: https://www.cnblogs.com/xiaotiaohu/p/17197948.html