簡體   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