首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >这是我的项目,我的所有点击功能都不起作用,但我在屏幕上正确地呈现数据。我怎么才能修好它?

这是我的项目,我的所有点击功能都不起作用,但我在屏幕上正确地呈现数据。我怎么才能修好它?
EN

Stack Overflow用户
提问于 2022-03-03 06:33:05
回答 1查看 397关注 0票数 0

这是我的livewire组件类代码

这是我的livewire组件类代码,这是我的livewire组件类代码,这是我的livewire组件类代码。

代码语言:javascript
运行
复制
  <?php
    
    namespace App\Http\Livewire;
    use Livewire\WithPagination;
    use Livewire\Component;
    use App\Models\student;
    
    class Students extends Component
    {       
    
        public $selectData= true;
        public $createtData= false;
        public $updateData= false;
    
        public $name;
        public $email;
        public $country;
    
        public $studentID;
        public $edi_name;
        public $edi_email;
        public $edi_country;
    
        public $total_student;
        use WithPagination;
        
        public function render()
        {  $this->total_student=student::get();
            $student=student::orderBy('studentID','ASC')->paginate(100);
    
            return view('livewire.students',['student'=>$student])->extends('layouts.app');
       }
    
       public function showform()
       {
             dd('kawish');
           $this->selectData=false;
           $this->createtData=true;
       }
    
       public function resetField()
       {
           $this->$name="";
           $this->$email="";
           $this->$country="";
    
        $this->studentID;
        $this->edi_name="";
        $this->edi_email="";
        $this->edi_country="";
    
       }
    
       public  function create()
       {    
           $student=new student();
           $this->validate([
               'name'=>'required',
               'email'=>'required',
               'country'=>'required',
           ]);

//这是我的直播线

代码语言:javascript
运行
复制
           $student->name=$this->name;
           $student->email=$this->email;
           $student->country=$this->country;
    
           $result =$student->save();
           $this->resetField();
    
           $this->selectData=true;
           $this->createtData=false;
    
       }
       public function edit($studentID)
       {
        $this->selectData=false;
        $this->updateData=true;
    
        $student= student::findorFail($studentID);
        $this->studentID=$student->studentID;
        $this->edi_name=$student->name;
        $this->edi_email=$student->email;
        $this->edi_country=$student->country;
       }
       public function update($studentID)
       {
        
        $student= student::findorFail($studentID);
        $this->validate([
            'edi_name'=>'required',
            'edi_email'=>'required',
            'edi_country'=>'required',
        ]);
    
        $student->name=$this->edi_name;
        $student->email=$this->edi_email;
        $student->country=$this->edi_country;
        $result =$student->save();
        $this->resetField();
    
        $this->selectData=true;
        $this->updateData=false;
       }
       public function delete($studentID){
           $student= student::findorFail($studentID);
           $result=$student->delete();
    
       }
    }

//这是我的生活电线//这是我的生活电线

,这是我对同一个类的视图

这是我对同一个classT的视图,他是我对同一个类的视图。

代码语言:javascript
运行
复制
<div>
  @section('title','students')
     @section('content')


      <div class=" container">
        <div class="mt-5">
          <div class=" card">
            <div class=" card-header">
              <div class=" d-flex justify-content-between">
                <h3>users ({{count($total_student)}})</h3>
                <div>
                  <button wire:click='showform' class="btn btn-success">Add User</button> *//error
                </div>
                </div>
            </div>
          </div>
        </div>

  • 列表项

{{--表列表--}} @if ($selectData==true) ID名称Email Country Options @forelse ( $student as $item ){ $item->studentID}{$项目->名称}} {$项目->电子邮件}{$项目->国家}编辑删除@空#记录未找到@endforelse @endif {{-创建数据--}} @if ($createtData==true)添加数据输入名称@error('name') {{ $message } @enderror输入电子邮件@error(' Email ') { $message }}@enderror输入Country @error('country') {{ $message }} @enderror Save@endif {{-更新数据--}} @if ($updateData==true)更新数据输入名称@error('edi_name'){{ $message }} @enderror输入电子邮件@error('edi_email') { $message } @enderror输入Country @error('edi_country') {{ $message }} @enderror更新@endif @endsect

//这是我的生活电线//这是我的生活电线

我的布局代码

代码语言:javascript
运行
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>@yield('title')</title>
    <!-- CSS only -->
             <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" 
             integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
     @livewireStyles
</head>
<body>
    <div class="container-fluid bg-dark">
        <div class=" container p-4">
            <h2 class="text-center text-white">Laravel Livewire Crud</h2>
        </div>
    </div>

<div>
    @yield('content')
</div>
 
    @livewireScripts
</body>
</html>

\*\*my routing\*\*

代码语言:javascript
运行
复制
<?php

use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use App\Http\Livewire\Students;


// Route::view('/', 'app');

Route::get('/', Students::class);

这里是它的endsssss这里是它的endsssss

EN

回答 1

Stack Overflow用户

发布于 2022-08-15 20:40:14

删除组件视图中的@部分。活线组件需要从一个。您可以扩展组件中的部分,使其如下所示

代码语言:javascript
运行
复制
  public function render()
        {  $this->total_student=student::get();
            $student=student::orderBy('studentID','ASC')->paginate(100);
    
            return view('livewire.students',['student'=>$student])->extends('layouts.app')->slot('content");
        }

您可以像这样拥有组件视图

代码语言:javascript
运行
复制
      <div class=" container">
        <div class="mt-5">
          <div class=" card">
            <div class=" card-header">
              <div class=" d-flex justify-content-between">
                <h3>users ({{count($total_student)}})</h3>
                <div>
                  <button wire:click='showform' class="btn btn-success">Add User</button> *//error
                </div>
                </div>
            </div>
          </div>
        </div>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71332970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档