我想知道如何在本机脚本/ vue JS中获得数组的长度?
我的代码:
export default {
data: () => {
return {
i: 0,
log: [],
img:[
"~/Pictures/home.png",
"~/Pictures/test.png"
],
};
},
你有个主意吗?
答案 0 :(得分:1)
您可以为此使用computed property。
假设您想要img
数组的长度:
export default {
data() {
return {
img: ["~/Pictures/home.png", "~/Pictures/test.png"]
};
},
computed: {
imgArrayLength() {
return this.img.length;
}
}
};
</script>