【问题标题】:Livewire - Increased time each time doing requestLivewire - 每次请求时都会增加时间
【发布时间】:2023-03-29 07:44:01
【问题描述】:

每次我执行相同的操作请求时,运行时间都会不断增加。有什么办法可以解决吗?

在我的刀片中:


<div class="col-md-6">
    <div class="form-group @error('promotion') has-error @enderror required">
        <label>Promotion</label>
        <select class="full-width" wire:model="promotion" wire:change="select_promotion">
            <option></option>
            @foreach($data_promotion as $data)
            <option value="{{$data->promotion_id}}" {{$promotion==$data->promotion_id?'selected':''}}>{{$data->promotion_name}}</option>
            @endforeach
        </select>
        <x-jet-hold wire:loading.class="visible"></x-jet-hold>
        <x-jet-loading wire:loading.class="visible" wire:target="select_group"></x-jet-loading>
    </div>
    @error('promotion')
        <label id="promotion-error" class="error" for="promotion">{{ $message }}</label>
    @enderror
</div>

我的方法:


public function select_promotion()
{
        $this->type_proposal_tap = 'normal';
        $this->modal = 0;
        $this->source_budget = 1;
        $promotion = PromotionNames::select('mst_promotion.*','mst_promotion_form.form_field','mst_promotion_form.form_upload')
                                    ->where(['mst_promotion.promotion_id'=>$this->promotion])
                                    ->join('mst_promotion_form','mst_promotion_form.form_id','mst_promotion.form_id')->first();

       ----other code----
}

做同样的事情,即选择选择选项并调用 select_promotion() 方法,livewire 时间请求不断增加,如下所示:

找了半天,发现方法调用执行异常,所以看起来同一个数据查询是这样执行的:

如何阻止它?即使我在方法 mount() 或 render() 中没有进程

【问题讨论】:

    标签: php laravel laravel-livewire livewires


    【解决方案1】:

    您不需要在选择元素中同时使用连线指令(模型和更改)。如果您使用该属性绑定到后端,您可以获得它的生命周期钩子

    <div class="col-md-6">
      <div class="form-group @error('promotion') has-error @enderror required">
        <label>Promotion</label>
          <select class="full-width" wire:model="promotion">
            <option></option>
            @foreach($data_promotion as $data)
             <option value="{{$data->promotion_id}}">{{$data->promotion_name}}</option>
            @endforeach
            </select>
       //............     
    </div>
    
    public function updatedPromotion($value)
    {
       dd($value);
       $this->select_promotion();
    }
    

    如果您尝试使用更改操作,您可以这样做

    <select class="full-width" wire:change="$emit('select_promotion', $event.target.value)">
            <option></option>
    //.......
    
    protected $listeners = [
       'select_promotion'
    ];
    
    public function select_promotion($value)
    {
       $this->promotion = $value;
       //..... the rest of this method
    }
    
    

    【讨论】:

    • 谢谢,它的工作,先生。但是我的加载组件有问题
    • 你好。请打开另一个问题并添加与之相关的代码以查看可能发生的情况。问候
    • 已经解决了先生,我在选择时保留 wire:model="promotion" 并在加载组件时使用 wire:target="promotion"
    猜你喜欢
    • 2019-05-12
    • 1970-01-01
    • 2018-12-25
    • 2011-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    • 2018-11-04
    相关资源
    最近更新 更多