JavaScript Proxy $wire

Hi,

I am trying to use the JavaScript Proxy ($wire) with live and alpine.js.

I managed to retrieve the property cities in my livewire component with $wire.get(‘cities’):

public $cities = [
[
“id” => 1,
“fullname” => “Ábelová”,
“shortname” => “Ábelová”,
“zip” => “98513”,
“district_id” => 33,
“region_id” => 1,
“use” => 1,
“latitude” => “48.4108169”,
“longitude” => “19.4317411”,
“slug” => “abelova”,
“created_at” => null,
“updated_at” => null,
]];

I am trying to set the property in alpine but i get always the error "Cannot read property $wire of undefined:

Do I have to create setter in the component or do you have any idea why I cant read the property?

$wire is a magic property and if I’m not mistaken is converted to something like livewire.findComponent(id) and this conversions happens only inside component view. If you doing this outside component you need to know component id find it and then do the .get()

Hi,

thanks for the reply.

Yes, I know I did it using alpine, but sometimes i can just get the properties but not set them. I think there was a problem with the array passed since I am using alpine.

BR