Inertia.js 中的空白页面 - 控制台中没有错误

2023-12-25

我已经尝试了 8 个小时左右让 Inertia.js 与 Laravel 和 VueJS 一起使用。我得到的是一个空白页面,控制台中没有错误消息(实际上是前端和后端控制台)。相反,我拥有的是一个空白页面和一个选项卡,其中加载动画无限运行。

我在网上搜索了答案。我没有发现任何真正有帮助的东西。

我想要实现的是获得类似于我正在使用的 YouTube 教程的结果(https://www.youtube.com/watch?v=XEW2d2XHkAk https://www.youtube.com/watch?v=XEW2d2XHkAk).


这是 web.php 文件的内容:

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

//
Route::get("/hello", function () {
    return inertia("Hello");
});

这是 app.js 文件的内容:

import Vue from 'vue'
import { createInertiaApp } from '@inertiajs/inertia-vue'
import { InertiaProgress } from '@inertiajs/progress'

InertiaProgress.init()

createInertiaApp({
  resolve: name => require(`./Pages/${name}`),
  setup({ el, App, props }) {
    new Vue({
      render: h => h(App, props),
    }).$mount(el)
  },
})

以下是 Kernel.php 文件的内容:

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array
     */
    protected $middleware = [
        // \App\Http\Middleware\TrustHosts::class,
        \App\Http\Middleware\TrustProxies::class,
        \Fruitcake\Cors\HandleCors::class,
        \App\Http\Middleware\PreventRequestsDuringMaintenance::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \App\Http\Middleware\HandleInertiaRequests::class,
        ],

        'api' => [
            'throttle:api',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],
    ];

    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
        'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
    ];
}

以下是 app.blade.php 文件的内容:

<!DOCTYPE html>
<html>
  <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>
  </head>
  <body>
    @inertia
  </body>
</html>

以下是 Hello.vue 文件的内容:

<template>
    <div>hi there i am the hello page</div>
</template>

<script>
    export default {};
</script>


好的。我认识的一个人找到了答案。

所以我对这两个命令感到困惑:

npm run watch

versus

php artisan serve

浏览器将打开一个选项卡,其中应用程序在端口 3000 上运行。因此我所需要做的就是更改浏览器中的端口。例如:

http://127.0.0.1:8000/你好 http://127.0.0.1:8000/hello

编辑:总而言之,您使用“npm run watch”来确保您的应用程序在浏览器中始终是最新的“并运行“php artisanserve”将您的应用程序提供给浏览器。您运行这两个命令,但您必须使用运行“php artisanserve”命令后提供给您的端口。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Inertia.js 中的空白页面 - 控制台中没有错误 的相关文章

随机推荐

  • 截断 UILabel 中的部分文本

    我的要求是 我需要在标签中显示文本 如果文本长度太大而无法容纳在一行中 我需要在末尾截断它 这样只有最后几个字符 通常是黑白 1 1000 的数字 因此文本长度可能会有所不同 是可见的 并且其之前的文本被 截断 所以文本看起来像 abcde
  • kubernetes skydns 转发请求失败

    我正在创建一个 1 个主节点 2 个节点的 kubernetes 集群 我正在尝试基于以下内容创建 skydns apiVersion v1 kind ReplicationController metadata name kube dns
  • ANACONDA navigator 无法启动-from win32com.shell import shellcon, shell

    我已经下载并安装了 ANACONDA Anaconda3 2020 02 Windows x86 但是 我发现我无法启动 ANACONDA 导航器 因此我尝试使用命令行并获得了反馈 from win32com shell import sh
  • 无法获取 dicom 图像以在 python 中显示

    我正在尝试在 opencv python 中显示 DICOM 图像 我正在使用 pydicom 库 然后添加 API 来使用 DOTNET 创建一个完整的 DICOM 查看器 该查看器运行 python 当然 C 使用流程实例调用 pyth
  • AMD 相当于 NvOptimusEnablement

    对于 Intel NVIDIA 双 GPU Optimus 设置 应用程序可以导出NvOptimusEnablement如中所解释的Optimus渲染策略 pdf http developer download nvidia com dev
  • ADP 文件中的数据库连接信息在哪里? [关闭]

    Closed 这个问题是无关 help closed questions 目前不接受答案 用户输入了他们每天使用的旧 Access 数据库和表单项目的票证 他们说使用数据库时找不到数据库 自大学以来我就没有使用过 MS Access 来设计
  • 如何轻松打包分析核心转储所需的库(即 packcore)

    HPUX 上可用的 GDB 版本有一个名为 packcore 的命令 该命令创建一个包含核心转储 可执行文件和所有库的 tarball 当尝试在不同的机器上调试核心转储时 我发现这非常有用 在 Linux 机器上的 GDB 标准版本中是否有
  • 使用 Autofac 与 AutoMapper Profile 进行 IoC

    我使用 AutoMapper 一段时间了 我的个人资料设置如下 public class ViewModelAutoMapperConfiguration Profile protected override string ProfileN
  • WiX 卸载 - 在重新启动管理器之前关闭应用程序

    我有一个用 WiX 完成的安装程序 安装完成后 它会启动一个应用程序 在资源管理器进程中注入一些代码 目前 当我卸载时 重新启动管理器会启动并关闭我的应用程序和资源管理器 相反 我想手动关闭我的应用程序 这是通过在命令行上使用 exit 再
  • Scala 推断类型参数 - 推断为“Nothing”的类型边界

    我正在尝试编写一个简单的查询 monad 但无法获取我的generic键入注释正确 我的第一次尝试如下 为了简洁而大大简化 case class Person val name String abstract class Schema T
  • 将实体集合拆分为 n 个部分

    我有一个数据库表 首先 我想按日期时间分组 然后我只想选择有 n 个项目的组 我的班级是这样的 public class VisitDate public int Id get set public int VisitMeDate get
  • 使用 CIFilter 在 CALayer 层次结构中渲染视频

    在我的 iOS 应用程序的 UI 中 我显示了一个复杂的层次结构CALayers 其中一层是AVPlayerLayer显示视频CIFilter实时应用 使用AVVideoComposition asset applyingCIFilters
  • 如何在具有悬停事件的 jQuery 动画中正确使用 stop() ?

    我使用下面的方法来制作一些动画 但是当我快速地进出鼠标并将其停在div the fadeIn 不起作用 并且div保持透明 grids hover function gridscontrol stop fadeIn 200 function
  • 无法解析 android 中的符号 setOnClickListener

    当我运行这个程序时 它反复说 无法解析符号setOnClickListener 请任何人帮我解决这个问题 import android support v7 app AppCompatActivity import android cont
  • MySQL数据包含š和ć等特殊字符,但它们显示为“?”在网页上。为什么?

    我正在尝试从表中检索包含该值的行Boris Borenovi 反而 Boris Borenovi 被返回 我的MySQL数据库和表都有utf8 unicode ci整理集 我的 PHP 页面显示表中的数据 包含以下标题 我尝试过charse
  • 使用 xgboost 绘制特征重要性

    当我绘制特征重要性时 我得到了这个混乱的图 我有超过 7000 个变量 我知道内置函数只选择最重要的 尽管最终的图表不可读 这是完整的代码 import numpy as np import pandas as pd df pd read
  • 使用 Python 在 Selenium 中运行 javascript

    我对硒完全陌生 我想在下面的代码中执行一个javascript片段 如代码中注释的那样 但不能这样做 请帮忙 from selenium import webdriver import selenium from selenium comm
  • 适用于 Windows CE 的 Microsoft C++ STL 有何差异?

    有谁知道 Microsoft 在 Windows CE 上实现 STL 与完整的桌面 STL 之间的差异的完整列表吗 我使用的是WinCE 6 0 搭配VS 2005 我有点惊讶他们似乎删除了这么多东西 对于 GCC 来说几乎是一样的 谢谢
  • 使 incron inotify 工作时遇到问题

    所以在亚历克斯回答之后 这是我的步骤 创建外壳代码 root ip touch mylog sh root ip nano mylog sh 复制 mylog sh 中的代码 bin bash echo File 1 created gt
  • Inertia.js 中的空白页面 - 控制台中没有错误

    我已经尝试了 8 个小时左右让 Inertia js 与 Laravel 和 VueJS 一起使用 我得到的是一个空白页面 控制台中没有错误消息 实际上是前端和后端控制台 相反 我拥有的是一个空白页面和一个选项卡 其中加载动画无限运行 我在