php - 我正在尝试使用 Laravel Livewire,但它不起作用。请找到以下代码并为我提供解决方案
问题描述
这是 Laravel Livewire 中的注释部分,该函数必须呈现注释,但这里显示的是硬编码注释,而不是 addNewComment 函数呈现的注释。
飞——comments.php
<div class = "flex justify-center">
<h1>Comments</h1>
<input type="text" placeholder="What is in Your Mind" />
<button wire:click="addNewComment">ADD</button>
</div>
@foreach($comments as $comment)
<div class="rounded border shadow p-3 my-2">
<p>{{$comment['id']}}</p>
<p style="color:red;"> {{$comment['creator']}} </p>
<p> {{$comment['created_at']}} </p>
<p> {{$comment['body']}} </p>
</div>
@endforeach
public $comments = [
[
'id' => '1',
'body' => 'New Comment',
'created_at' => '1 min ago',
'creator' => 'TESTER'
]
];
public function addNewComment()
{
$this->comments[] =
[
'id' => '111',
'body' => $this->newComment,
'created_at' => Carbon::now()->diffForHumans(),
'creator' => 'TESTER'
];
}
public function render()
{
return view('livewire.comments');
}
}
File-- Welcome.blade.php
<head>
<title>Live Wire</title>
<script src="{{ asset('js/app.js') }}" defer></script>
<livewire:styles />
<livewire:scripts />
</head>
<body>
<livewire:comments />
</body>
addNewComment 函数是可点击的,但不起作用。
解决方案
推荐阅读
- java - 在不同的 jdk 版本中运行 spring boot 应用程序
- java - 带有改造 2.0 Android 的多部分请求 请求时间过长
- python - 如何在整个代码中使用 __init__ 方法中定义的变量?
- excel - 使用 go 循环遍历特定的 excel 列
- git - 从 svn 转换为 git 后如何从分支名称中删除远程源
- .net-core - 将 Dynamics CRM SDK 与 .NET Core 结合使用
- c# - 如何使用#pragma 警告禁用 CA1814?
- javascript - 用 span 替换部分字符串
- javascript - Chrome 控制台中奇怪的“e”或“t”表示什么
- excel - 从 Crystal Reports 2016 v14 中删除所有分页符 -> Excel 导出