一开始是静态实现的:
this.$refs.treeMenuRef1.style.display = "none";
this.$refs.treeMenuRef2.style.display = "none";
this.$refs.treeMenuRef3.style.display = "none";
this.$refs.treeMenuRef4.style.display = "none";
this.$refs.treeMenuRef5.style.display = "none";
this.$refs.treeMenuRef6.style.display = "none";
现在想实现动态,但是会报错:
Uncaught TypeError: Cannot read property 'style' of undefined
for(a=1;a<=count;a++)
{
var x='treeMenuRef'+a;
this.$refs.x.style.display = "none";
}
请问我该如何做?
for(a=1;a<=count;a++)
{
var x='treeMenuRef'+a;
this.$refs[x].style.display = "none";
}
可以用jquery试试,直接获取dom然后操作这个dom就可以了
this.$refs[x].style.display = "none";