Home > database >  bootstrap-vue - show button based on boolean
bootstrap-vue - show button based on boolean

Time:11-11

When I click Launch centered modal, I expect the modal hide the buttons x,cancel and ok because showButton is false.

After I click the show button, the button of the modal should be shown because now showButton is true.

How should I do it?

enter image description here

App.vue

<template>
  <div id="app">
    <b-button v-b-modal.modal-center>Launch centered modal</b-button>
    <b-modal id="modal-center" centered title="BootstrapVue">
      <p class="my-4">Vertically centered modal!</p>
      <button @click="setShowButton">Show Button</button>
    </b-modal>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      showButton: false,
    };
  },
  methods: {
    setShowButton() {
      this.showButton = true;
    },
  },
};
</script>

<style>
#app {
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

Codesandbox
https://codesandbox.io/s/flamboyant-herschel-62wpt?file=/src/App.vue:0-587

CodePudding user response:

You can use the hide-header-close and hide-footer properties. Documented here. Modal docs

<template>
  <div id="app">
    <b-button v-b-modal.modal-center>Launch centered modal</b-button>
    <b-modal
      id="modal-center"
      centered
      title="BootstrapVue"
      :hide-header-close="!this.showButton"
      :hide-footer="!this.showButton"
    >
      <p class="my-4">Vertically centered modal!</p>
      <button @click="setShowButton">Show Button</button>
    </b-modal>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      showButton: false,
    };
  },
  methods: {
    setShowButton() {
      this.showButton = true;
    },
  },
};
</script>

<style>
#app {
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

Example https://codesandbox.io/s/hungry-architecture-zrcqj?file=/src/App.vue

  • Related