When transferring an object from a blade template to a Vue component through props, it may become undefined

I'm facing an issue where I am attempting to send an array from an asynchronous method in the controller to a Vue component using props within a blade template. However, when I try to log it in the Vue component, it shows up as undefined. Here is the code snippet:

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 have done some research and came across suggestions that using async in the controller may be causing the issue as the object is still empty when it reaches the Vue component. However, I am not entirely sure about this. Am I implementing it incorrectly?

Answer №1

When it comes to binding props, keep in mind that while it may work with strings and integers, it might not be as effective with array or object data. You can find more information about this at this link.

To properly bind data, consider the following syntax:

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

Additionally, if you frequently bind data to Vue components in Blade, you may want to explore Inertia.js, which offers a more efficient way to render Vue components with props.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AngularJS and Gulp: Enhancing Static Assets with Revisioning

I have implemented the gulp-rev module to re-vision static assets in my source files. It generates new file names for CSS, JS, and HTML files by appending a hash code to it. Before : app.js After : app-2cba45c.js The issue I am facing is that in my An ...

What is the best way to connect click events with ExtJS template elements?

Is there a way to assign a click event to each link tag without directly embedding onclick=.... in the XTemplate code? new Ext.XTemplate( '<ul>', '<tpl for="."><li><a href="#{anchor}">{text}</a></li& ...

What is the best way to conceal a website's URL?

Is it possible to hide the actual URL some.otherdomain.com and show only domain.com to visitors of my website? I am looking for a way to mask the URL, perhaps through .htaccess or javascript. Is there any solution available? ...

What is the process for generating a null result cursor upon publication?

Is it possible to return an empty cursor in Meteor? Meteor.publish('example', function(id) { check(id, Match.Maybe(String)) if (!this.userId) return [] }) Although I want the publication to return an empty result when the user is not lo ...

Using Selenium and Python to showcase the source of an image within an iframe

My goal is to automatically download an image from shapeNet using Python and selenium. I have made progress, but I am stuck on the final step. from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.s ...

Tips for setting up and utilizing browserify in a Laravel project?

Currently, I am working on a project using Laravel and incorporating React.js for dynamic views. However, in order to organize my react scripts into different modules, I realized the need to install browserify. Unfortunately, I am unfamiliar with npm and c ...

Discovering the point of exit for a mouse from an image

Visit this website to see the effect in action: I am curious about how the image scrolls into and out of the direction where the mouse enters and leaves. Can you explain how this is achieved? ...

How can values be passed to child components in Vue when using component tags for dynamically switching components?

Is there a way to pass values to children components in Vue when using the component tag? It appears that I am unable to pass values to a child component using the component tag without using v-if: <component :is="showNow"></component> ...

Is Apache required for running NodeJs?

Recently, I set up a web project on my local machine following a tutorial. With the help of XAMPP, I was able to install MySQL and Apache to run my Node.JS backend. Now, I'm looking into hosting the project on an external server to make it accessible ...

What is the best way to create a general getter function in Typescript that supports multiple variations?

My goal is to create a method that acts as a getter, with the option of taking a parameter. This getter should allow access to an object of type T, and return either the entire object or a specific property of that object. The issue I am facing is definin ...

Reserve a spot for a credit card in 4-digit format with VueJS

When I enter a credit card number, I want to automatically insert a space after every 4 digits. For example: 0000 0000 0000 0000 I am currently using vue js and have come across examples using jquery, but I prefer not to use jquery. Any help would be appr ...

Is there a way to prevent continuous repetition of JavaScript animated text?

I'm working on a code that displays letters and words one by one, but I can't figure out how to stop it from repeating. Can someone help me with this? <div id="changeText"></div> <script type="text/javascript"> var te ...

What is the best way to manage the changing selection in a drop-down list?

Can someone help me with a coding issue I am facing? <select name="txtTK" > <option value="None">---</option> <option value="Mat">Materials</option> <option value="Cate">Category</option> <option ...

Why is my Typescript event preventDefault function ineffective?

Despite all my efforts, I am still unable to prevent the following a tag from refreshing the page every time it's clicked. <p> <a onClick={(e) => handleClick} href="&qu ...

AngularJS ng-repeat causing data binding to constantly refresh

If I were to have a $scope setup similar to this: $scope.array = [ { a: 1, b: 2 }, { a: 2, b: 1 }]; And a corresponding view: <div>A: <div ng-repeat="obj in array">{{obj.a}}</div> </div> My question is, if the AngularJS watche ...

Passing the current loop object in Vue JS when clicked

I have a data set up where I am utilizing a loop. If an admin clicks on the user section, a pop-up will appear. The code snippet is as follows: On the User List page <template> <header class="headings"> <div class="hea ...

AngularJS: incorporating modules across distinct controllers

Imagine we have two distinct AngularJS controllers housed in separate files that are both referenced in an HTML document. Here's how it looks: //controller1.js "use strict"; var someApp = angular.module('MYAPP'); //var someApp = angular.mod ...

Ways to avoid a situation where a populated host folder takes precedence over a container folder that has been mounted

I'm in the process of compiling assets for a Laravel project using Docker. To achieve this, I've set up a service called npm based on the following Dockerfile: FROM node:16-alpine as node WORKDIR /usr/src ADD ./resources ./resources COPY ["pac ...

The Street View feature on Google Maps API is now showcasing a cool,

I have been attempting to showcase the interior of various businesses using the Google Maps API street view feature. Initially, I was able to retrieve the place_id and then use it to access any available street view panoramas. However, this functionality s ...

Disable menu bar | customize menu bar in electronJS

I am developing an Angular application with Electron.js. Due to the specific design requirements of my app, which is browser-based, I do not require or want the default Electron.js menu or menu bar to be displayed. Is there a way to remove it from my app ...