【发布时间】:2019-02-25 22:11:54
【问题描述】:
我想将this library 导入到我的 laravel 项目中。我已经运行 npm install vue-simple-lightbox 然后在我的刀片模板中我有这个代码
@extends('layouts.app')
@section('content')
{{-- some html code --}}
<div class="row">
</div>
<div class="row">
<lightbox id="mylightbox" :images="images" :image_class="'img-responsive img-rounded'" :album_class=" 'my-album-class' " :options="options"></lightbox>
{{-- more html code --}}
</div>
@endsection
<style type="text/css">
.dropdown, .dropdown-menu {
width: 100%;
}
</style>
@section('scripts')
// import the library here?
<script type="text/javascript">
let app = new Vue({
el: '#app',
data() {
return {
images : [
{
src : 'https://cdn.rawgit.com/vrajroham/vrajroham.github.io/85d64ac5/imgs/img1.jpg',
title : 'Image 2'
},
{
src : 'https://cdn.rawgit.com/vrajroham/vrajroham.github.io/85d64ac5/imgs/img2.jpg',
title : 'Image 3'
},
{
src : 'https://cdn.rawgit.com/vrajroham/vrajroham.github.io/85d64ac5/imgs/img3.jpg',
title : ''
},
{
src : 'https://cdn.rawgit.com/vrajroham/vrajroham.github.io/85d64ac5/imgs/img4.jpg',
title : ''
},
],
options : {
closeText : 'X'
}
};
},
mounted() {
},
});
</script>
@endsection
我应该在哪里导入库?我尝试使用此代码window.Lightbox = require('vue-simple-lightbox'); 将其导入app.js 文件,但是我该如何使用它呢?刀片模板似乎不知道什么是“灯箱”。
我收到了这个错误
[Vue 警告]:未知的自定义元素:- 您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。
导入库然后在刀片模板中使用它的正确方法是什么?谢谢!
【问题讨论】:
-
在标记文件中包含复杂的 JavaScript 逻辑通常是不好的做法。您应该将其分离在一个 JS 文件中,然后您可以使用 import 语句,然后使用 laravel mix 编译该文件