[英]Laravel 8 Jetstream || Undefined variable: _instance (View: C:\xampp\htdocs\veye-website\resources\views\vendor\jetstream\components\modal.blade.php
I am trying to use Laravel 8 Livewire Modal Popup for data entry with going on another page.我正在尝试使用 Laravel 8 Livewire Modal Popup 进行数据输入并进入另一个页面。 But I get undefine the variable _instance and not able to understand it.
但是我没有定义变量 _instance 并且无法理解它。
@entangle($attributes->wire('model'))
@entangle($attributes->wire('model'))
This line creates this error when I remove this from views/vendor/jetstream/components/modal.blade.php.当我从 views/vendor/jetstream/components/modal.blade.php 中删除它时,这一行会产生此错误。 the error will go.
错误会消失。
Line no 34. 34号线。
<div id="<?php echo e($id); ?>" x-data="{ show: <?php if ((object) ($attributes->wire('model')) instanceof \Livewire\WireDirective) : ?>window.Livewire.find('<?php echo e($_instance->id); ?>').entangle('<?php echo e($attributes->wire('model')->value(
x-show="show"
x-on:close.stop="show = false"
x-on:keydown.escape.window="show = false"
class="fixed top-0 inset-x-0 px-4 pt-6 sm:px-0 sm:flex sm:items-top sm:justify-center"
style="display: none;">
This was causing me much angst too but I think I found the solution: as @georgy-malanichev says, you can only call Livewire methods from inside a Livewire component (and not from inside a Blade component or any other custom components).这也让我很焦虑,但我想我找到了解决方案:正如@georgy-malanichev 所说,您只能从Livewire组件内部(而不是从Blade组件或任何其他自定义组件内部)调用 Livewire 方法。
Given you are trying to use the component inside resources/views/dashboard.blade.php
, the solution is to:鉴于您正在尝试使用
resources/views/dashboard.blade.php
的组件,解决方案是:
artisan make:livewire MyDashboard
artisan make:livewire MyDashboard
创建一个 livewire 组件artisan make:livewire MyDashboard
<x-app-layout>
and </x-app-layout>
in dashboard.blade.php
and paste it into views/livewire/my-dashboard.blade.php
dashboard.blade.php
<x-app-layout>
和</x-app-layout>
之间的所有内容并将其粘贴到views/livewire/my-dashboard.blade.php
@livewire('my-dashboard')
inside the x-app-layout
tags and Bob's your uncle (it should start working)x-app-layout
标签中添加@livewire('my-dashboard')
并且 Bob 是你的叔叔(它应该开始工作) To help you understand what's going on, if you look at the source code for the modal component, you'll see a line like: show: @entangle($attributes->wire('model')),
.为了帮助您了解发生了什么,如果您查看模态组件的源代码,您将看到如下一行:
show: @entangle($attributes->wire('model')),
。 I'm not sure how to describe exactly what this does, but, essentially, @entangle()
is expecting an instance of the "model" Livewire object and it's not finding one.我不确定如何准确描述它的作用,但本质上,
@entangle()
期待“模型”Livewire 对象的实例,但它没有找到。
It's not finding it because it's getting called from a non-livewire component.它没有找到它,因为它是从非 livewire 组件调用的。 Once you put it inside a Livewire component, it starts working.
一旦你把它放在一个 Livewire 组件中,它就会开始工作。
I hope the additional details makes things clearer.我希望额外的细节能让事情更清楚。
I was getting the same error but in my case it was the fact that I had x-data="{ open: @entangle('showDropdown') }"
outside of the LiveWire component.我遇到了同样的错误,但就我而言,这是因为我在 LiveWire 组件之外有
x-data="{ open: @entangle('showDropdown') }"
。 Once I moved it inside the component template, where it should be, the issue went away.一旦我将它移到组件模板中,它应该在的位置,问题就消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.