【问题标题】:How to fix trix editor in laravel 5.8如何在 laravel 5.8 中修复 trix 编辑器
【发布时间】:2019-04-24 17:07:33
【问题描述】:

我正在尝试在表单中添加 trix 编辑器。它出现了,但工具栏被禁用,它不起作用。经过一番研究,我发现它在我的布局文件的标题中,所以我将它移到正文的末尾并删除了“延迟”,现在 trix 编辑器消失了。

布局文件

<!-- Scripts -->
<script src="{{ asset('js/app.js') }}"></script>   
 @yield('scripts')
</body>
</html>

我想要 trix 编辑器的字段

<div class="form-group">
   <label for="content">Content</label>
   <input id="content" type="hidden" name="content">
   <trix-editor input="content"></trix-editor>
</div>

trix js 和 css

@section('scripts')
<script src="https://cdnjs.cloudflare.com/ajax/libs/trix/1.1.1/trix.js"></script>
@endsection

@section('css')
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/trix/1.1.1/trix.css">
@endsection

【问题讨论】:

  • 我尝试清理一下代码格式。请确保此处有足够的信息,以便其他人可以使用您发布的代码来重现您的问题,以便他们可以帮助您找出问题所在。

标签: javascript jquery editor laravel-5.8 trix


【解决方案1】:

--> 作曲家需要 te7a-houdini/laravel-trix

--> php artisan vendor:publish --provider="Te7aHoudini\LaravelTrix\LaravelTrixServiceProvider"

--> php artisan 迁移

在你的页面中使用类似

<html>
    <head>
        @trixassets
    </head>

    <body>
        <form method="POST" action="route('article.store')">
            @csrf
            @trix(\App\Article::class, 'content')
            <input type="submit">
        </form>    
    </body>
</html>

【讨论】:

    【解决方案2】:

    我在这里制作了演示 trix 编辑器,它在 laravel 5.8.14 v 中运行良好

    <!doctype html>
    <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <title>Laravel</title>
            <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/trix/1.1.1/trix.css">
            <style>
                html, body {
                    background-color: #fff;
                    color: #636b6f;
                    font-family: 'Nunito', sans-serif;
                    font-weight: 200;
                    height: 100vh;
                    margin: 0;
                }
    
                .full-height {
                    height: 100vh;
                }
    
                .flex-center {
                    align-items: center;
                    display: flex;
                    justify-content: center;
                }
    
                .position-ref {
                    position: relative;
                }
    
                .top-right {
                    position: absolute;
                    right: 10px;
                    top: 18px;
                }
    
                .content {
                    text-align: center;
                }
    
                .title {
                    font-size: 84px;
                }
    
                .links > a {
                    color: #636b6f;
                    padding: 0 25px;
                    font-size: 13px;
                    font-weight: 600;
                    letter-spacing: .1rem;
                    text-decoration: none;
                    text-transform: uppercase;
                }
    
                .m-b-md {
                    margin-bottom: 30px;
                }
            </style>
        </head>
        <body>
            <div class="flex-center position-ref full-height">
                @if (Route::has('login'))
                    <div class="top-right links">
                        @auth
                            <a href="{{ url('/home') }}">Home</a>
                        @else
                            <a href="{{ route('login') }}">Login</a>
    
                            @if (Route::has('register'))
                                <a href="{{ route('register') }}">Register</a>
                            @endif
                        @endauth
                    </div>
                @endif
    
                <div class="content">
                    <div class="title m-b-md">
                        Laravel
                    </div>
                     <trix-editor input="content"></trix-editor>
                </div>
            </div>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js" type="text/javascript"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/trix/1.1.1/trix.js"></script>
        </body>
    </html>
    

    你忘记添加 jquery 了吗?

    【讨论】:

      【解决方案3】:

      您在section('scripts') 中提到的 trix 代码的 js 链接,而不是包含在“脚本”部分中。直接将链接粘贴到 html 的主 HEAD 部分,可能是 layouts.app 中的链接。

      或者你也可以像以前一样做,只是改变一些代码:

      1. 在您的 html 头部部分中,在其他提到的 SCRIPT 标记下方添加像 @YIELD('CSCRIPTS') 一样的 yield,确保在 yield 中使用新名称。
      2. 在 html 的 head 部分中,您还会看到其他 SCRIPT 标签,如果存在则删除 DEFER。
      3. 最后,转到您的 SECTION 所属的刀片并将其更改为 @SECTION('CSCRIPTS')。
      4. 效果很好。

      但你也会看到另一个脚本标签,在那里并删除 DEFER 关键字。 其他保持不变,完美运行

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-06
        • 1970-01-01
        • 2020-03-05
        相关资源
        最近更新 更多