为livewire组件的公共财产获取价值时遇到问题

时间:2020-10-10 02:20:35

标签: laravel-livewire

我在项目中的livewire上工作,遇到问题。

我的livewire模型和刀片文件如下:

LivewireCounter.php

class LivewireCounter extends Component
{
    public $count;
    public function render()
    {
        return view(Constant::LIVEWIRE_COUNTER_BLADE);
    }

    public function mount($count = 0)
    {
        $this->count = $count + 1;
    }
    public function increment()
    {
        if($this->count >= Constant::LIVEWIRE_COUNTER_MAX)
        {
            $this->count = Constant::LIVEWIRE_COUNTER_MAX;
        } else {
            $this->count++;
        }
    }
    public function decrement()
    {
        if($this->count <= Constant::LIVEWIRE_COUNTER_MIN)
        {
            $this->count = Constant::LIVEWIRE_COUNTER_MIN;
        } else {
            $this->count--;
        }
    }
}

livewire-counter.blade.php

    <div>
    <div class="flex inline-block relative w-64">
        <button class="px-1" wire:click="decrement">-</button>
        <h1>{{ $count }}</h1>
        <button class="px-1" wire:click="increment">+</button>
    </div>
</div>

我有一个优惠券刀片文件,该文件使用livewire来跟踪用户订购的优惠券。

coupon-show.blade.php

    @extends(Constant::LAYOUTS_APP)

@section(Constant::LAYOUTS_CONTENT)

<div class="container">
            <div>
                <p class="text-4xl text-extrabold text-gray-900">{{ $CouponSetting->name }}</p>
                @livewire('livewire-counter', ['count' => 9])
            </div>
        {{$count}}
    </div>
</div>

@endsection

我遇到的问题是我无法在coupon-show.blade.php文件中检索$count值。我认为应该可以通过刀片视图访问livewire组件的公共属性?

ErrorException 未定义的变量:计数(查看:/Applications/MAMP/htdocs/XXX/resources/views/layouts/coupons/coupon-show.blade.php)

知道为什么吗?

0 个答案:

没有答案