如何在本机脚本(vueJS)中获取数组的长度

时间:2020-07-15 10:06:28

标签: arrays vue.js nativescript variable-length-array

我想知道如何在本机脚本/ vue JS中获得数组的长度?

我的代码:

export default {
    data: () => {
        return {
            i: 0,
            log: [],
            img:[
                "~/Pictures/home.png",
                "~/Pictures/test.png"
                ],
        };
    },

你有个主意吗?

1 个答案:

答案 0 :(得分:1)

您可以为此使用computed property

假设您想要img数组的长度:

export default {
  data() {
    return {
      img: ["~/Pictures/home.png", "~/Pictures/test.png"]
    };
  },
  computed: {
    imgArrayLength() {
      return this.img.length;
    }
  }
};
</script>