[英]InertiaJS with Laravel & Vue2: Cannot redefine property: $inertia
I'm not sure why I am getting this error:我不确定为什么会收到此错误:
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
and this warning:这个警告:
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)
I followed the docs as closely as I could.我尽可能密切地关注文档。 I'm using Vue2 and Laravel 8. I can't find anyone with the same issues anywhere.
我正在使用 Vue2 和 Laravel 8。我在任何地方都找不到有同样问题的人。 The error claims that 'App' is no longer used, but the docs for Vue2 use it in their example.
该错误声称不再使用“App”,但 Vue2 的文档在他们的示例中使用了它。 I'm confused, what am I missing?
我很困惑,我错过了什么?
Here is my code:这是我的代码:
resources/js/app.js
: 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
: 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
: web.php
:
Route::inertia('/drafts', 'drafts');
I had the same problem.我有同样的问题。
Here is how your app.js file must look like:以下是您的 app.js 文件的外观:
https://inertiajs.com/client-side-setup https://inertiajs.com/client-side-setup
summarizing:总结:
./pages/${name}
).then((module) => module.default), by require( ./Pages/${name}
).default,./pages/${name}
).then((module) => module.default),通过 require( ./Pages/${name}
).default,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.