0

我正在为我的应用程序尝试引导 vue 选项卡。我想禁用所有选项卡单击,但想使用导航按钮浏览选项卡。

但是,当我尝试增加选项卡索引时,它会自动再次设置为零。

有没有办法禁用选项卡单击,但通过上一个和下一个按钮导航它们。

new Vue({
  el: '#app',
  data: {
      tabIndex:0
   }
})
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css"/>
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css"/>

<script src="https://unpkg.com/vue"></script>
<script src="//unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>


<div id="app">
<b-card no-body >
  <b-tabs warning pills card vertical v-model="tabIndex" class="generictab" ref="wizard">
    <b-tab title="Tab Contents 1">
              <b-row>
              <b-col sm="12">
                <b-form-group>
                  <label for="name">Name</label>
                  <b-form-input type="text" id="name" placeholder="Enter your name"></b-form-input>
                </b-form-group>
              </b-col>
          </b-row>
    </b-tab>
    <b-tab title="Tab Contents 2" :disabled="!(tabIndex==2)">
      Tab Contents 2
    </b-tab>
    <b-tab title="Tab Contents 3" :disabled="!(tabIndex==3)">
      Tab Contents 3
    </b-tab>
  </b-tabs>
      <div class="text-center">
      <b-button-group class="mt-2">
        <b-btn @click="tabIndex--">Previous</b-btn>
        <b-btn @click="tabIndex++">Next</b-btn>
      </b-button-group>
      <br>
      <span class="text-muted">Current Tab: {{tabIndex}}</span>
    </div>
</b-card>
</div>

4

1 回答 1

2

根据我的理解,您希望通过单击下一步和上一个按钮而不是单击选项卡名称来导航。这是工作示例。希望能帮助到你。

new Vue({
  el: '#app',
  data: {
      tabIndex:0
   }
})
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css"/>
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css"/>

<script src="https://unpkg.com/vue"></script>
<script src="//unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
<style>
  .disabledTab{
      pointer-events: none;
  }
</style>

<div id="app">
<b-card no-body >
  <b-tabs warning pills card vertical v-model="tabIndex" class="generictab" ref="wizard">
    <b-tab title="Tab Contents 1" title-item-class="disabledTab">
              <b-row>
              <b-col sm="12">
                <b-form-group>
                  <label for="name">Name</label>
                  <b-form-input type="text" id="name" placeholder="Enter your name"></b-form-input>
                </b-form-group>
              </b-col>
          </b-row>
    </b-tab>
    <b-tab title="Tab Contents 2" title-item-class="disabledTab">
      Tab Contents 2
    </b-tab>
    <b-tab title="Tab Contents 3" title-item-class="disabledTab">
      Tab Contents 3
    </b-tab>
  </b-tabs>
      <div class="text-center">
      <b-button-group class="mt-2">
        <b-btn @click="tabIndex--">Previous</b-btn>
        <b-btn @click="tabIndex++">Next</b-btn>
      </b-button-group>
      <br>
      <span class="text-muted">Current Tab: {{tabIndex}}</span>
    </div>
</b-card>
</div>

于 2018-05-25T14:49:27.057 回答