首页 > 解决方案 > bootstrap-vue - 基于布尔值显示按钮

问题描述

当我单击时Launch centered modal,我希望模态隐藏按钮xcancel并且ok因为 showButton是错误的。

单击 后show button,应该显示模式的按钮,因为 nowshowButton是真的。

我该怎么做?

在此处输入图像描述

应用程序.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

标签: javascripthtmlcssvue.jsbootstrap-4

解决方案


您可以使用hide-header-closehide-footer属性。记录在这里。模态文档

<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>

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


推荐阅读