php - Laravel livewire:你将如何实现等效于 Vue 的 v-if v-else
问题描述
我正在尝试使用 LiveWire 编写我的第一个示例,我想做一些简单的事情...
<div v-if="active">
Active things
</div>
<div v-else>
Inactive things
</div>
<button @click="toggle" type="button">toggle</button>
我已经用php artisan make:livewire sample
,构建了我的示例组件
sample.blade.php:
<div>
<div wire:model="active">
Active things
</div>
<div wire:model="!active">
Inactive things
</div>
</div>
<button wire:click="toggle">toggle</button>
我只添加的组件:
public $active=true;
public function toggle() {
$this->active = !$this->active;
}
当然,它不起作用。我可以使用普通刀片的指令,但我对 Livewire 的主要兴趣是能够在不重新加载页面的情况下更改 DOM。
什么是等价的?
解决方案
你可以简单地这样做
{{-- Don t forget to alway wrap the component in a div --}}
<div>
<div>
@if($active) Active @else Inactive @endif things
</div>
<button wire:click="toggle">toggle</button>
</div>
推荐阅读
- python - 查找压缩二值图像的压缩率
- c - 双输入不正确 eventhoug 转换器是
- matlab - 用傅里叶级数表示指数函数
- php - 如何在 PHP 中获取具有长连续数字的连接数字或字符串 PHP?
- python - 二十一点游戏多轮系统
- c# - 我的 ASP.NET 3 Core MVC 上的浏览器链接问题
- vue.js - 带有参数和计算属性的 Vuex getter
- java - 在 Spring Data JPA 中,如何通过调用外部实体实例上的方法来创建和持久化内部实体
- list - 将 MFCC 与视频帧匹配
- mysql - 在 MySQL 和 go-sql-driver/mysql 之间更新了不一致的行