繁体   English   中英

带有 Laravel 和 Vue2 的 InertiaJS:无法重新定义属性:$inertia

[英]InertiaJS with Laravel & Vue2: Cannot redefine property: $inertia

我不确定为什么会收到此错误:

Uncaught TypeError: Cannot redefine property: $inertia
    at Function.defineProperty (<anonymous>)
    at Object.install (app.js:108)
    at Function.Vue.use (app.js:233295)
    at Module../resources/js/app.js (app.js:246829)
    at __webpack_require__ (app.js:20)
    at Object.0 (app.js:253385)
    at __webpack_require__ (app.js:20)
    at app.js:84
    at app.js:87

这个警告:

Registering the Inertia Vue plugin via the "app" component has been deprecated. Use the new "plugin" named export instead.

import { plugin } from '@inertiajs/inertia-vue'

Vue.use(plugin)

我尽可能密切地关注文档。 我正在使用 Vue2 和 Laravel 8。我在任何地方都找不到有同样问题的人。 该错误声称不再使用“App”,但 Vue2 的文档在他们的示例中使用了它。 我很困惑,我错过了什么?

这是我的代码:

resources/js/app.js

import { App, plugin } from '@inertiajs/inertia-vue'
import Vue from 'vue'

Vue.use(App)
Vue.use(plugin)

InertiaProgress.init()

Vue.component('drafts', require('./pages/Drafts').default)

const el = document.getElementById('app')

new Vue({
  render: (h) =>
    h(App, {
      props: {
        initialPage: JSON.parse(el.dataset.page),
        resolveComponent: (name) =>
          import(`./pages/${name}`).then((module) => module.default),
      },
    }),
}).$mount(el)

resources/views/app.blade.php

<!DOCTYPE html>

<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>{{ config('app.name', 'AppealMaker') }}</title>
    <!-- Styles -->
    <link href="{{ mix('css/app.css') }}" rel="stylesheet">
    <script src="{{ mix('js/app.js') }}"></script>
</head>

<body>
    @inertia
</body>

</html>

web.php

Route::inertia('/drafts', 'drafts');

我有同样的问题。

以下是您的 app.js 文件的外观:

https://inertiajs.com/client-side-setup

总结:

  • 移除:Vue.use(App)
  • 更改: import( ./pages/${name} ).then((module) => module.default),通过 require( ./Pages/${name} ).default,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM