【发布时间】:2018-12-02 22:27:07
【问题描述】:
为了显示引导模式,我们可以使用 data-toggle 属性。例如:
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#msg">Open Modal</button>
我想通过使用 vue bool 变量数据来显示模态。这是我的组件:
Vue.component('modal', {
delimiters: ['[[', ']]'],
props: {
id: String,
hidden: Boolean
},
data: function () {
return {
}
},
computed: {
getStyle: function() {
if(this.hidden)
return "display: hidden;"
return "display: block;"
}
},
methods: {
},
template: `
<div class="modal fade" v-bind:class="{show: !hidden}" role="dialog" :style="getStyle" :id="id">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<slot name="header"></slot>
</div>
<div class="modal-body">
<slot></slot>
</div>
</div>
</div>
</div>
`
})
比在 html 中我有:
<div id="msg_modal">
<modal :id="'msg'" :hidden='isHidden'>
{{ message }}
</modal>
</div>
在脚本中:
<script>
var msg_modal = new Vue({
el: '#msg_modal',
data: {
isHidden: false
}
})
</script>
之后,我的模式可见,但行为与单击“打开模式”按钮不同。例如,我无法通过单击模态边界来关闭模态。
提前感谢您的帮助。
编辑: 我通过使用 jquery 临时修复了这个问题
computed: {
id_selector: function() {
return "#"+this.id;
}
},
methods: {
show: function() {
this.modal('show');
},
hide: function() {
this.modal('hide');
},
toggle: function() {
this.modal('toggle');
},
modal: function(action) {
$(this.id_selector).modal(action);
}
},
有没有人知道没有 jquery 的解决方案?
【问题讨论】:
标签: javascript html vuejs2 bootstrap-4 vue-component