如何在js代码中获取组件的名称?

时间:2020-08-14 07:37:25

标签: laravel-livewire alpine.js

在laravel 7 / livewire 1.3 / alpine 2应用中阅读 https://laravel-livewire.com/docs/alpine-js#communicating-with-js

我尝试使用高山方法从我用命令创建的组件中读取数据

php artisan make:livewire admin/facilities 

,并且在组件app / Http / Livewire / Admin / Facilities.php中,我具有:

class Facilities extends Component
{
    ...
    public $updateMode = 'browse';

    public function render()
    {
        
        return view('livewire.admin.facilities.container', [
           ...
        ]);
    }

以及在resources / views / livewire / admin / facilities / container.blade.php中:

   ...
            hello::<div x-text="hello()"></div>
            editorTitle::<div x-text="editorTitle()"></div>
   ...

<script>

    function facilityEditorComponent() {
        return {
            hello: function () {
                return "Hello!123567"
            },
            editorTitle: function () {
                let component = window.livewire.find('admin.facilities')
                console.log(component)
                
                var updateMode = component.get('updateMode')
                console.log('$updateMode::')
                console.log($updateMode)
                
                return "editorTitle"
            },
        }
    }

</script>

但是在上面的方法中,var component是未定义的,sdo引用它时出错... 我的组件名称是哪个?我可以在页面来源中找到它吗?

谢谢!

0 个答案:

没有答案