具体写法可以有两种:

第一种:在函数内部声明变量,

var company = [], hushu = [], bili = [];
console.log("company",company,"hushu",hushu,"bili",bili);
for(var i = 0 ;i<arr.length;i++){
   company.push(arr[i].company);
   hushu.push(arr[i].hushu);
   bili.push(arr[i].dianscale);
}
console.log("company1",company,"hushu1",hushu,"bili1",bili);

第二种:在data中先声明在接收。

data(){
    return{
        companyArr:[],
        hushuArr:[],
        biliArr:[]
    }   
},

//方法里面的部分
for(var i = 0 ;i<arr.length;i++){
        this.companyArr.push(arr[i].company);
        this.hushuArr.push(arr[i].hushu);
        this.biliArr.push(arr[i].dianscale);
}
console.log("companyArr",this.companyArr,"hushuArr",this.hushuArr,"biliArr",this.biliArr);

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐