提问者:小点点

Laravel Livewire事件(如单击)不起作用。我用的是拉威尔7


我最近开始学习Laravel Livewire。当我第一次创建Livewire组件时,一切都很顺利。但是当我尝试创建一个新的时,事件和函数不再工作。Livewire类中的属性/变量可以读取,但我确实无法让函数正常工作。这是我的密码

resources/views/livewire/step。刀身php

<div>
    <button id="sampleBtn" wire:click="increment">&plus;</button>
    {{-- Doesn't change value. Still zero --}}
    <h3> {{$steps}} </h3> 
</div>

app\http\Livewire\Step。php

<?php

namespace App\Http\Livewire;
   
use Livewire\Component;
    
class Step extends Component
{
    public int $steps = 0;
        
    public function increment()
    {
        $this->steps++;
    }

    public function render()
    {
        return view('livewire.step');
    }
}

资源/视图/待办事项

@extends('layouts.app')
@section('content')
<div class="container">
  <a href="/todo" class="btn btn-info">&larr;</a>
  <div class="col-6 offset-3 my-3">
    <div class="card mx-auto my-3">
      <div class="card-header">
        <h4 class="card-title">Create</h4>
      </div>
      <div class="card-body">
        <x-alert/>
        <form action="{{route('todo.store')}}" method="post" class="form">
          @csrf
          <div class="form-group">
            <input type="text" name="title" id="title" class="form-control" placeholder="Title">
          </div>
          <div class="form-group">
            <textarea name="description" id="description" cols="30" rows="5" class="form-control" placeholder="description"></textarea>
          </div>
          <div class="form-group">
            <input type="text" name="step" class="form-control" placeholder="add step here">
          </div>
          <button type="submit" id="createBtn" class="btn btn-block btn-primary">Add task</button>
        </form>
        {{-- I placed this outside the form because it undergoes through validation. I don't want it to be validated yet. --}}
        <div id="forLivewire">
          @livewire('step')
        </div>   
      </div>
    </div>
  </div>
</div>
@endsection

我尝试将livewire脚本与其他脚本一起放在HTML头部。它仍然不起作用。另外,我正在使用引导。

另外,我目前正在YouTube上学习一个教程。

编辑:我在控制台上得到一个“err_aborted404”错误


共1个答案

匿名用户

问题出在Livewire脚本中。我发布了资产,现在它可以工作了!

php artisan vendor:publish --force --tag=livewire:assets