【发布时间】:2018-08-03 22:38:43
【问题描述】:
我正在使用 Vue+Laravel,我想制作一个带有 2 个选项卡的模式窗口。我有两个按钮,每个按钮都必须打开某个连接的选项卡。
按钮是blade模板中的地方:
<button @click="openModal('login')">
<button @click="openModal('register')">
//Vue component also is placed in blade template
<auth-component :show="showModal" :active_tab="activeTab" @close="showModal = false"></auth-component>
/resources/assets/js/app.js:
我想将openModal() 参数 传递给组件...
const app = new Vue({
el: '#app',
data: {
showModal: false,
activeTab: '',
},
methods: {
openModal(tab) {
this.activeTab = tab;
this.showModal = true;
}
},
});
... 并使用该 参数 作为 Vue prop 将某些 bootstrap-tab 设置为在 Vue 组件中处于活动状态:
AuthComponent.vue:
<div class="modal-mask" @click="close" v-show="show">
<div class="modal-wrapper">
<div class="modal-container" @click.stop>
<b-card no-body>
<b-tabs card>
<b-tab title="Login" :active="active_tab === login">
<b-tab title="Register" :active="active_tab === register">
</b-tabs>
</b-card>
</div>
</div>
</div>
...
props: ['show', 'active_tab'],
但是我当前的代码不起作用。没有控制台错误。打开模式后,只有第一个选项卡(登录)始终处于活动状态。
更新:我搬到了
<b-tab title="Login" :active="active_tab === login">
<b-tab title="Register" :active="active_tab === register">
我看到在 Vue 控制台中需要选项卡获取 active: true 属性。但是active: true 注册选项卡无论如何都是display: none。所以我猜想将active 属性设置为true 不足以让标签内容真正可见。
【问题讨论】:
-
如果我的
active_tab属性在单击按钮后有需要的值,如果有任何方法可以调试,请告诉我。我使用console.log()在app.js中检查activeTab并没问题。 -
active_tab将是一个字符串,所以它应该是:active="active_tab === 'login'" -
@Matt 我试过了。我签入了需要选项卡获取
active参数的Vue devtools。但它的类不会更改为active show -
另外一种快速调试 props 的方法是从计算中注销。例如
computed: { activeTabDebug() { console.log(this.active_tab); } }
标签: javascript laravel vue.js