Vue.js初学者: - )
我有一些testblock
个div,它们有teststep
个子div。有一个testblock
切换按钮可切换所有testblock
个元素,每个testblock
都有一个切换按钮可切换其子teststeps
:
<div id="app">
<div><button class="btn btn-lg btn-primary" @click="showTestblock = !showTestblock">Toggle testblocks</button></div>
<div v-if="showTestblock">Testblock-1</div>
<div v-if="showTestblock"><button class="btn btn-lg btn-primary" @click="showTeststep = !showTeststep">Toggle teststeps</button></div>
<div v-if="showTeststep">Teststep-1a</div>
<div v-if="showTeststep">Teststep-1b</div>
<div v-if="showTestblock">Testblock2</div>
<div v-if="showTestblock"><button class="btn btn-lg btn-primary" @click="showTeststep = !showTeststep">Toggle teststeps</button></div>
<div v-if="showTeststep">Teststep-2a</div>
<div v-if="showTeststep">Teststep-2b</div>
<div v-if="showTestblock">Testblock3</div>
<div v-if="showTestblock"><button class="btn btn-lg btn-primary" @click="showTeststep = !showTeststep">Toggle teststeps</button></div>
<div v-if="showTeststep">Teststep-3a</div>
<div v-if="showTeststep">Teststep-3b</div>
</div>
Vue代码:
new Vue({
el: '#app',
data: {
showTestblock: false,
showTeststep: false
}
})
有两个问题:
teststep
切换所有测试步骤,而不仅仅是切换步骤
具体testblock
。在JQuery中我会添加一个ID,但是有一个Vue
更好的方法吗?teststeps
并且testblock
切换按钮为
单击,测试块不再显示,但teststeps
是。如何关闭孩子?更新:
使用正确的嵌套更新代码:
<div id="app">
<div><button class="btn btn-lg btn-primary" @click="showTestblock = !showTestblock">Toggle testblocks</button>
<div v-if="showTestblock"><span>Testblock-1</span>
<div v-if="showTestblock"><button class="btn btn-lg btn-primary" @click="showTeststep = !showTeststep">Toggle teststeps</button>
<div v-if="showTeststep">Teststep-1a</div>
<div v-if="showTeststep">Teststep-1b</div>
</div>
</div>
<div v-if="showTestblock"><span>Testblock-2</span>
<div v-if="showTestblock"><button class="btn btn-lg btn-primary" @click="showTeststep = !showTeststep">Toggle teststeps</button>
<div v-if="showTeststep">Teststep-2a</div>
<div v-if="showTeststep">Teststep-2b</div>
</div>
</div>
<div v-if="showTestblock"><span>Testblock-3</span>
<div v-if="showTestblock"><button class="btn btn-lg btn-primary" @click="showTeststep = !showTeststep">Toggle teststeps</button>
<div v-if="showTeststep">Teststep-3a</div>
<div v-if="showTeststep">Teststep-3b</div>
</div>
</div>
</div>
</div>