Home > Back-end >  VUE data object get attribute/value
VUE data object get attribute/value

Time:09-01

data() {
    return {
      Joke: {visible:true, ordering:1},
      Weather: {visible:true, ordering:3},
      Forecast: {visible:true, ordering:2},
      Nasa: {visible:true, ordering:4},
      Notes: {visible:true, ordering:5},
      Bored: {visible:true, ordering:6},
      
    };
  },

When I try and loop through this and return each item:

 for (var item in this.$data) {
    console.log(item[0]);
  }

All I get is the name of the object rather than the data within.

Any help appreciated - I need to access the value of "ordering" for each of them

CodePudding user response:

 for (let item in this.$data) {
  console.log(this.$data[item]);

}

去mdn上面复习一下for in 的 用法

  • Related