gpt4 book ai didi

vuejs2 - 当值不为空时 VueJS 显示按钮

转载 作者:行者123 更新时间:2023-12-04 01:50:49 25 4
gpt4 key购买 nike

我对使用 VueJS 很陌生,想知道是否有一种方法可以只显示一个按钮(包含一个插槽),以便仅显示是否为插槽提供了按钮值。

我使用的是BootstrapVue Modals,代码如下:

我无法在代码段中成功运行模态,但下面是已打开模态的屏幕截图。

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>

<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://cdnjs.cloudflare.com/ajax/libs/vue/2.0.3/vue.js"></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>
</head>

<body>
<div id="app">
<b-btn @click="showModal" class="modalBtn">
<slot name="modalOpenBtn">Open Me</slot>
</b-btn>

<b-modal ref="myModalRef" hide-header no-fade hide-backdrop>
<h1 class="font-18 text-black font-weight-bold mb-5">Merchant Closed</h1>
<p class="font-14 text-black mb-20">please be aware that the merchant that you are viewing is currently closed. Feel free to add items to your cart but you will not be able to place your order until they’re open.</p>

<div slot="modal-footer" class="w-100 d-flex align-items-center">
<b-btn class="btn btn-teal btn-block font-14 w-100" block @click="hideModal">
<slot name="modalCloseBtn">btn 1</slot>
</b-btn>

<b-btn class="btn btn-teal btn-block font-14 w-100" block @click="hideModal">
<slot name="modalOkBtn">btn 2</slot>
</b-btn>
</div>
</b-modal>
</div>

<script>
new Vue({
el: '#app',
components: { App },
methods: {
showModal () {
this.$refs.myModalRef.show()
},
hideModal () {
this.$refs.myModalRef.hide()
}
}
});
</script>
</body>

</html>

Opened Modal Screenshot

最佳答案

您可以使用 Vues v-if 指令有条件地渲染元素:

// generic
<button v-if="myBooleanCondition">...</button>

// exmaple
<button v-if="something == true">...</button>

https://v2.vuejs.org/v2/guide/conditional.html

关于vuejs2 - 当值不为空时 VueJS 显示按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53184534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com