下面是我的App/Http/Livewire/Test。php
文件
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class Test extends Component
{
public $name = 'mike';
public function render(){
return view('livewire.test');
}
public function clickTest(){
$this->name = 'Joe';
}
}
下面是我的resources/views/livewire/test。刀身php
<div>
hello {{$name}}
</div>
下面是我的资源/视图/测试。刀身php
<html>
<head>
<title>test page</title>
@livewireStyles
<script src="{{ asset('js/app.js') }}"></script>
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
</head>
<body>
<div>
<livewire:test /> //this line is working fine
<button wire:click="clickTest">test</button> //this line is not working
</div>
@livewireScripts
</body>
</html>
我能够在页面加载上获得Hello mike
,但是当我单击测试按钮时,它不会更改为Joe
。当我检查我的网络选项卡时,它看起来像是点击事件甚至没有被触发,并且它不能到达clickTest()
函数
您的按钮需要移动到组件中:
<div>
hello {{$name}}
<button wire:click="clickTest">test</button>
</div>