Laravel 8Inertia js-出现Vue错误'app.js:30559 [Vue警告]:创建的钩子中出现错误:“错误:找不到模块...”

问题描述

我已经安装了使用Jetstream(惯性js堆栈)的Laravel 8安装。所有Jetstream提供的视图均正常运行。

问题是当我创建一个呈现新Vue模板的新Route时,在控制台中出现此错误

app.js:30559 [Vue warn]: Error in created hook: "Error: Cannot find module './Test'"

在web.PHP中创建的我的路线

Route::get('/test',function() {
    return Inertia\Inertia::render('Test');
});

“ Test.vue”文件位于“ resources / js / Pages”目录中。

<template>
            <h2 class="font-semibold text-xl text-gray-800 leading-tight">
                Testing
            </h2>
</template>

app.js

require('./bootstrap');

import Vue from 'vue';

import { InertiaApp } from '@inertiajs/inertia-vue';
import { InertiaForm } from 'laravel-jetstream';
import PortalVue from 'portal-vue';

Vue.use(InertiaApp);
Vue.use(InertiaForm);
Vue.use(PortalVue);

const app = document.getElementById('app');

new Vue({
    render: (h) =>
        h(InertiaApp,{
            props: {
                initialPage: JSON.parse(app.dataset.page),resolveComponent: (name) => require(`./Pages/${name}`).default,},}),}).$mount(app);

知道为什么找不到Test.vue模板吗?

解决方法

只需要运行'npm run dev'

,

也许其他人像我一样来到这里-我必须在Chrome中打开开发者控制台,并确保在Network标签中选中了disable cache

最重要的是,必须进入我的服务器并执行php artisan optimize以清除缓存的视图。

,

您应该运行以下命令:npm run watch

它将跟踪您的所有更改并更新应用程序。