Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

87
Visualizações
object is undefind when passing from blade to vue component using props

I'm trying to pass an array from async method in the controller to a vue component using props through the blade, but I'm getting undefined when I try to console.log it in the vue component, this is my code:

Controller:

    public function index(){


           $pool = Pool::create();

           $pool[] = async(function () {

                     return Rfm::all();

           })->then(function ($output) {

           $this->results=$output;
           });

           await($pool);

    return view ("/dashboard", ["data" => $this->results]);

Blade:

   <div id="total_customers">
       <total-customers :data="{{$data}}"></total-customers>
   </div>

Vue component:

export default {
props: ['data'],

data() {
    return {
        
    };
},
mounted() {
    console.log(this.data);
}
};

I've searched and read somewhere that using async in the controller would be the problem as the object is still empty when it render to vue component, but I'm not sure about that, am i doing it wrong?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Binding props that way might work with strings and integers but doesn't work with array/object data: https://laravel.com/docs/9.x/blade#blade-and-javascript-frameworks

The following should work:

<total-customers :data="{{ Js::from($data) }}"></total-customers>

Addition: Might want to look into https://inertiajs.com/ if you bind data to vue components in blade a lot, its a nicer way to render vue components with props

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda