如何通过复选框有条件地改变Bootstrap-vue tooltip文本?

问题描述 投票:0回答:1

Bootstrap-vue工具提示文字如何通过复选框有条件的更改?如何进入tooltip文本进行更改?任何帮助都将是非常感激的。

Vue组件中的一个复选框试图改变一个tooltip。

<template>
  <div class="text-center">
    <b-button v-b-tooltip.hover.right="tooltipText" variant="outline-primary">
      <div v-bind:class="{ active: checkbox1 }">
        {{ username }}
      </div>
    </b-button>  
  </div>
</template>

<script>

export default {
    props: ['username', 'checkbox1'],

    data() {
      return {
         show: true,
         tooltipTextContent: 'hello tooltip',
     }      
},

methods: {

     tooltipText() {
          if (!this.checkbox1) {
            return this.tooltipTextContent
          } else {
            return `${this.tooltipTextContent} changed`
          }
    }
},
} 

</script>
<style scoped>

.active {
    color: red;
}
</style>
vue.js tooltip bootstrap-vue
1个回答
1
投票

你只需要给tooltip文本绑定一个可以更改的值,例如 computed:

new Vue({
  el: "#app",
  data: {
    username: 'Username1',
    checkbox1: false,
    tooltipTextContent: 'block'
  },
  computed: {
    tooltipText() {
      if (!this.checkbox1) {
        return this.tooltipTextContent
      } else {
        return `${this.tooltipTextContent} changed`
      }
    }
  }
})
.active {
  color: red;
}
<!-- Load required Bootstrap and BootstrapVue CSS -->
<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.min.css" />

<!-- Load polyfills to support older browsers -->
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CIntersectionObserver" crossorigin="anonymous"></script>

<!-- Load Vue followed by BootstrapVue -->
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>

<!-- Load the following for BootstrapVueIcons support -->
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue-icons.min.js"></script>

<div id="app">
  <div class="text-center">
    <b-button v-b-tooltip.hover.right="tooltipText" variant="outline-primary">
      <div v-bind:class="{ active: checkbox1 }">
        {{ username }}
      </div>
    </b-button>
  </div>
  <b-form-checkbox id="checkbox-1" v-model="checkbox1" name="checkbox-1">
    Change tooltip text?
  </b-form-checkbox>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.