关于简单情况的问题,我想将vue modal component添加到默认的Laravel项目中。 当我以这种方式注册时:
Vue.component('modal', {
template: '#modal-template'
})
new Vue({
el: '#app',
data: {
showModal: false
}
})
和这样的命名组件:
ModalComponent.vue
浏览器给我下一个错误。 Github repository
中的所有详细信息顺便说一句,也许最好用jQuery从引导程序中添加模式窗口,否则会很乱吗?
答案 0 :(得分:1)
您应该有:
Vue.component('modal', require('./components/ModalComponent.vue'));
并在您的ModalComponent.vue
文件中:
<template>
<transition name="modal">
<div class="modal-mask">
<div class="modal-wrapper">
<div class="modal-container">
<div class="modal-header">
<slot name="header">
default header
</slot>
</div>
<div class="modal-body">
<slot name="body">
default body
</slot>
</div>
<div class="modal-footer">
<slot name="footer">
default footer
<button class="modal-default-button" @click="$emit('close')">
OK
</button>
</slot>
</div>
</div>
</div>
</div>
</transition>
</template>
<script>
export default {
}
</script>
view.blade.php
<div id="app">
<button id="show-modal" @click="showModal = true">Show Modal</button>
<!-- use the modal component, pass in the prop -->
<modal v-if="showModal" @close="showModal = false">
<!--
you can use custom content here to overwrite
default content
-->
<h3 slot="header">custom header</h3>
</modal>
</div>