如何解决在xhr
说明: 2种方式的数据绑定不起作用,变量的值不更新。
确切的复制步骤
-
清洁幼虫安装
-
livewire安装
-
livewire:进行测试
精简的,可复制的代码段
- livewire / Test.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class Test extends Component
{
public $text;
public function render()
{
return view('livewire.test');
}
}
- livewire / test.blade.php
<input type="text" wire:model="text">
{{$text}}
- welcome.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">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
<livewire:styles />
<style>
body {
font-family: 'Nunito';
}
</style>
</head>
<body class="antialiased">
<livewire:test/>
<livewire:scripts />
</body>
</html>
- 请求有效载荷
{fingerprint: {id: "p2OSso56TqMjMT4XN4Oo",name: "test",locale: "en"},…}
fingerprint: {id: "p2OSso56TqMjMT4XN4Oo",locale: "en"}
id: "p2OSso56TqMjMT4XN4Oo"
locale: "en"
name: "test"
serverMemo: {children: [],errors: [],htmlHash: "b6eb143a",data: {text: "te"},dataMeta: [],…}
checksum: "1949b7cded0c349a39cb3f8d9d36a92bd88d5c3a1b676544851ddd229d157c4c"
children: []
data: {text: "te"}
text: "te"
dataMeta: []
errors: []
htmlHash: "b6eb143a"
updates: [{type: "syncInput",payload: {name: "text",value: "test"}}]
0: {type: "syncInput",value: "test"}}
payload: {name: "text",value: "test"}
name: "text"
value: "test"
type: "syncInput"
上下文
- Livewire版本:2.2
- Laravel版本:8.10
- 浏览器:[Edge,Chrome,Opera]
解决方法
正如 Quirel 所写的,您的 test.blade.php
必须只有一个这样的根元素
<div>
<input type="text" wire:model="text">
{{$text}}
</div>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。