【问题标题】:bootstrap-vue - show button based on booleanbootstrap-vue - 基于布尔值显示按钮
【发布时间】:2021-12-23 14:05:37
【问题描述】:

当我单击Launch centered modal 时,我希望模态隐藏按钮xcancelok,因为showButton 是假的。

点击show button后,应该显示模态按钮,因为现在showButton为真。

我该怎么做?

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>

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

【问题讨论】:

    标签: javascript html css vue.js bootstrap-4


    【解决方案1】:

    您可以使用hide-header-closehide-footer 属性。记录在这里。 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>
    

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

    【讨论】:

    • 你不应该在模板中使用this.。你可以改用:hide-header-close="!showButton"
    猜你喜欢
    • 2021-11-07
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-19
    • 2021-06-07
    • 1970-01-01
    相关资源
    最近更新 更多