Ways to effectively access props in Vue.js without having to pass them through a div element

Currently, I have an API call being made in the create hook of my Vue root. After that call, a component is attempting to utilize the data returned from the API.

My inquiry is straightforward. Is it possible to have

<stage-execs></stage-execs>
without having to pass in job_execs = job_execs? I find the cleaner appearance of just using
<stage-execs></stage-execs>
appealing.

    <div id="vue-job">
    <div class="column">
        <div class="row">
            <stage-execs v-bind:job_execs=job_execs></stage-execs>
        <br><br>
    </div>
    </div>


<script>
    Vue.component('stage-execs', {
        delimiters: [ '[[', ']]' ],
        props: ['job_execs'],
        template: `
        <ul id="example-1">
          <h3>Stages</h3>
          <li v-for="item in this.job_execs">
            [[ item.build_id ]]
          </li>
        </ul>
        `,

var v_root = new Vue({
    delimiters: [ '[[', ']]' ],
    el: '#vue-job',
    data: {
        job_execs: []
    },
    created() {
        url="http://{{ api_endpoint }}"
        fetch(url)
            .then(response => response.json())
            .then(body => {
                for(i=0; i<body.length; i++){
                    this.job_execs.push({
                        'build_id': JSON.stringify(body[i].build_id),
                        'status': JSON.stringify(body[i].status.name),
                    })
                }
        })
        .catch( err => {
            console.log('Error Fetching:', url, err);
            return { 'failure': url, 'reason': err };
        });

    },
});

Answer №1

It is not possible to achieve that. Your best option is to remove the v-bind and replace it with :job_execs=job_execs. (The use of : is a shortcut for v-bind)

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

When using Vue 3 in my app, I discovered that all the TypeScript files are easily accessible through the browser console

I recently completed my Vue3 js app with Typescript, and I have noticed that all the Typescript files are easily accessible for anyone to view through the Sources tab of the browser console. The code is perfectly clear and readable. Is there a method to p ...

What is the best way to transfer static assets from an npm package to a nuxt project?

Has anyone successfully sent assets from an npm package to a nuxt application before? I have a vue component within an npm package with the following structure: -src/ -assets/ -noun-filter.svg In this npm package, the vector image is included in the v ...

execute a method within a component through the main Vue application

Just starting out with Vue and dipping my toes into components. Currently, I have the main script file for my new Vue app which includes a countdown function based on setInterval. In the same file, there's also a Vue component (a stamina bar created ...

Vue's drag-and-drop functionality is effective for dragging entire groups, but it does not work

Below is the code that enables dragging of groups in toListFetchRouteA1: <draggable id="first" data-source="juju" :list="toListFetchRouteA1" class="list-group" draggable=".item" group="a"> <div class="list-group-item item" v-for="teamfetch in ...

Executing VueJS keyup handler after the previous onclick handler has been executed

Link to example code demonstrating the issue https://codepen.io/user123/pen/example-demo I am currently facing an issue with a text field named search_val that has a watcher attached to it. The text field includes a v-on keyup attribute to detect when th ...

Displayed unfamiliar Obj characters on Google Chrome

Hey there, I'm new to Vue JS and Vuetify and could really use some help! I've been trying to display some HTML content from my data using v-html in Vue JS, but for some reason, strange OBJ symbols keep showing up. Here is a screenshot of what I ...

Creating a Copy of an Object in JavaScript that Automatically Updates When the Original is Changed

I am in the process of developing a planner/calendar website with a repeat feature. var chain = _.chain(state.items).filter({'id': 1}).head().value(); console.log(chain); After filtering one object, I am wondering how to create a duplicate of c ...

The Vue.js input for checkboxes and radios fails to toggle when both :checked and @input or @click are used simultaneously

Check out this example on JSFiddle! <script src="https://unpkg.com/vue"></script> <div id="app"> <label> <input type="checkbox" name="demo" :checked="isChecked" @input=" ...

Enjoy the seamless integration of SPA Vue frontend with backend Laravel 7 using Sanctum for

Having trouble with my Vue and Laravel Spa setup using Sanctum. When sending requests through axios, I keep getting a status of 204. When trying to retrieve user information, I'm getting an Unauthenticated error message. Not sure what's going wro ...

Repeated parameters when making a second login request with axios and sending data in url-encoded format

Implementing token-based authentication and sending urlencoded data via axios. Passing the user and password to the axios function with all parameters set as per documentation. import axios from 'axios' const params = new URLSearchParams() param ...

Vuejs allows objects to trigger the execution of methods through elements

My goal is to utilize a function in order to individually set the content of table cells. In this specific scenario, I aim to enclose the status with the <strong> - Tag (I refrain from modifying the template directly because it is stored within a com ...

Is there a way to extract only the value from the most recent request?

While working with VueJS, I have a handler for changes in an input field that looks like this: inputHandler(url, params){ const p = new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); xhr.open('POST&ap ...

What is the best way to access the child DOM of a Vue element?

Is there a way to access the child DOM element of a Vue component? In the code snippet below, I am trying to retrieve the <input> element nested within the <div>. var vm = new Vue({ el: '#box', data: { pick: true, a: & ...

Issue with Nuxt: Module needs to export a function: @turfhelpers [ERROR]

Can someone explain why I am receiving the error message Module should export a function: @turf/helpers after adding @turf/helpers to my buildModules in nuxt.config.js? nuxt.config.js // Plugins to run before rendering page: https://go.nuxtjs.dev/config-p ...

How can I set up a KeyboardEvent listener in JavaScript?

My attempt to use @keydown resulted in an error: Type 'Event | KeyboardEvent' is not assignable to type 'KeyboardEvent'. Type 'Event' is missing the following properties from type 'KeyboardEvent': altKey, c ...

Tips for efficiently querying an array of objects with dynamic search criteria in VueJs3?

I have a search feature that scans through Objects and displays results based on the chosen search parameter (ID, NAME). While searching by ID works perfectly, trying to search by name returns undefined. I'm puzzled as to why ID can be successfully s ...

Clearing form data after submitting in Laravel using axiosIn Laravel, utilizing

When working on my Laravel app, I encountered an issue while submitting a form using Vue and Axios. Despite my attempts to clear the input field after submission, it doesn't seem to work. HTML: <form method="post" enctype="multipart/form-data" v- ...

creating a Vuejs button function that will add together two given numbers

Help needed with VueJs code to display the sum of two numbers. Seeking assistance in developing a feature that calculates the sum only when the user clicks a button. Any guidance would be greatly appreciated! <!DOCTYPE html> <html lang="en"> ...

Struggling to access specific data within a JSON object? Wondering how to extract and display data from a JSON object in VUE?

Despite my extensive searching on Stack and the internet, I have not been able to find a solution to my problem. Currently, I am attempting to retrieve data from a JSON file located in the Vue src folder. The file contains three arrays with names that inc ...

Avoiding future clicks with a delay in VUE: A guide

Is there a way to prevent the next click for 600ms after an initial click? I want to temporarily "disable" all a tags for 600ms after one is clicked. Any help would be appreciated. VUE <ul> <li v-for="item in navigation" :key=& ...