【发布时间】:2021-01-29 21:52:51
【问题描述】:
说明: 2方式数据绑定不起作用,变量的值不会更新。
重现的确切步骤
-
干净的 laravel 安装
-
livewire 安装
-
livewire:进行测试
精简、可复制粘贴的代码 sn-ps
- 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>
- 请求Ppayload
{fingerprint: {id: "p2OSso56TqMjMT4XN4Oo", name: "test", locale: "en"},…}
fingerprint: {id: "p2OSso56TqMjMT4XN4Oo", name: "test", 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", payload: {name: "text", value: "test"}}
payload: {name: "text", value: "test"}
name: "text"
value: "test"
type: "syncInput"
上下文
- Livewire 版本:2.2
- Laravel 版本:8.10
- 浏览器:[Edge、Chrome、Opera]
【问题讨论】:
-
你遇到了什么错误。?
-
没有出现错误...
-
您的组件刀片中需要一个根元素。您现在有两个,一个文本和一个输入。将它们包裹在
<div>中。
标签: laravel data-binding laravel-livewire