如何让 @inertia 指令在 Laravel 的 InertiaJS 中工作?

问题描述 投票:0回答:2

我是 InertiaJS 的新手,无法让它在我的生产环境中运行。我的 Blade 模板中的 @inertia 指令似乎无法识别,它只是按字面意思呈现在页面上。它只是在浏览器中的

<body>
内显示“@inertia”。

在我的本地开发环境中,页面按预期加载,并且我看到了该组件。所以我拥有所有前端适配器并根据文档设置我的 app.blade.php 和 app.js。

使用 PHP 8.0、Laravel 7.30.4、InertiaJS 0.9.2。

// app.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
    <link href="{{ mix('/css/app.css') }}" rel="stylesheet" />
    <script src="{{ mix('/js/app.js') }}" defer></script>
    <title></title>
</head>
<body>
    @inertia
</body>
</html>
// app.js

import { createInertiaApp } from '@inertiajs/inertia-svelte'

createInertiaApp({
    resolve: name => require(`./Pages/${name}.svelte`),
    setup({ el, App, props }) {
        new App({ target: el, props })
    },
})

当我用确切的

<div id="app" ...></div>
替换 @inertia 指令时,我进入了我的开发环境,一切正常,我看到了该组件。

唯一的控制台错误是

Uncaught (in promise) TypeError: Cannot read property 'dataset' of null at resolve (app.js [...])
,但我想如果
<div id="app" ...></div>
不存在,这是可以预料的。 日志中没有服务器端错误。

我错过了什么?

php laravel inertiajs
2个回答
3
投票

我在生产环境中遇到了完全相同的问题。对我来说,这是一个缓存问题。尝试一下:

composer dump-autoload php artisan cache:clear php artisan config:clear php artisan view:clear
    

0
投票
我检查了有关更新存储在缓存文件夹(cache/packages.php、cache/services.php)中的文件的响应,它有效。 如果您尝试在共享托管中托管的项目中更新或添加惯性js,则更新这些文件非常有用

© www.soinside.com 2019 - 2024. All rights reserved.