最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - LiveComponent isn't updating the LiveProp value - Stack Overflow

programmeradmin0浏览0评论

I am trying to use the Symfony UX LiveComponent, firstly I tried to use the first exemple of the documentation:

// ArticleSearch.php
<?php

namespace App\Twig\Components;

use App\Repository\ArticleRepository;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\DefaultActionTrait;

#[AsLiveComponent]
class ArticleSearch
{
    use DefaultActionTrait;

    #[LiveProp(writable: true)]
    public string $search = '';

    public function __construct(private ArticleRepository $articleRepository)
    {
    }

    public function getArticles(): array
    {
        return $this->articleRepository->findBy(['title' => $this->search]);
    }
}

<!-- ArticleSearch.html.twig -->
<div {{ attributes }}>
    <input
        type="search"
        data-model="search"
    >

    <ul>
        {% for article in this.getArticles %}
            <li>{{ article.title }}</li>
        {% endfor %}
    </ul>
</div>

The attributes are showing, but the value of $search is never updating, so nothing happends.

It happends when I use the symfony local:server:start, can it cause a problem ?

Thanks

EDIT:

Here's the content of my app.js and bootstrap.js:

// app.js
import './bootstrap.js';
/*
 * Welcome to your app's main JavaScript file!
 *
 * This file will be included onto the page via the importmap() Twig function,
 * which should already be in your base.html.twig.
 */
import './styles/app.css';

console.log('This log comes from assets/app.js - welcome to AssetMapper! 
发布评论

评论列表(0)

  1. 暂无评论