javascript - Vue - 如何制作基于外部控制动态激活
问题描述
如何根据按下的按钮动态激活选项卡。我正在使用<b-tabs>
from bootstrap-vue
。在我下面的示例代码中,step
变量会根据按下的按钮进行更改,但无论如何选项卡始终处于活动状态。
<template>
<div>
<b-tabs>
<b-tab title="Step 1" :active="step === 1">
<br>step 1
</b-tab>
<b-tab title="Step 2" :active="step === 2">
<br>step 2
</b-tab>
<b-tab title="Step 3" :active="step === 3">
<br>step 3
</b-tab>
</b-tabs>
<button v-on:click="step = 1">Step 1</button>
<button v-on:click="step = 2">Step 2</button>
<button v-on:click="step = 3">Step 3</button>
</div>
</template>
<script>
export default {
data() {
return {
step: 0,
}
},
mounted() {
},
methods: {
},
}
</script>
解决方案
尝试使用v-model
如上所述in this example
而不是active
prop 如下:
<b-tabs v-model="step">
<b-tab title="Step 1" >
<br>step 1
</b-tab>
<b-tab title="Step 2" >
<br>step 2
</b-tab>
<b-tab title="Step 3" >
<br>step 3
</b-tab>
</b-tabs>
你的步骤应该从0
<button v-on:click="step = 0">Step 1</button>
<button v-on:click="step = 1">Step 2</button>
<button v-on:click="step = 2">Step 3</button>
推荐阅读
- laravel - 使用子域通配符时如何编写 api 测试
- reactjs - 反应材料表
- reactjs - 在 React 中键入检查事件 onKeyPress 的正确方法是什么?
- javascript - 在 laravel 上使用 SWAL 和 ajax 执行并确认删除
- jmeter - 如何在 Jmeter 中解决此会话 ID 问题?
- java - 附加额外字节的 UTF-16 编码
- video - 使用 ffmpeg windows explorer 扩展旋转视频
- python - 如何从嵌套列表中消除项目
- python-3.x - Dask - 如何取消并重新提交停滞的任务?
- spring - 在 Spring 中按用户区分的 RequestMapping