Props does not solely rely on Vue.js for data feeding

  1. My journey with learning vue has just started, and I recently incorporated a prop into my vue component. At first glance, the code appeared to be correct, but then something unexpected occurred.

import Vue from 'vue';
import App from './App.vue';
import vSelect from 'vue-select';
import Paginate from 'vuejs-paginate';
import 'vue-select/dist/vue-select.css';

Vue.config.productionTip = false;
Vue.component('paginate', Paginate);
Vue.component('v-select', vSelect);

window.onload = function () {
    var sections = document.getElementsByClassName("newsRoom");
    let length = sections.length;
    for (var i = length - 1; i >= 0; i--) {
        sections[i].setAttribute("id", 'jsNewsListGridContainer' + i);
        sections[i].setAttribute("ref", 'jsNewsListGridContainer' + i);
        var parentElements = sections[i].parentElement;
        var endpointurlhref = parentElements.dataset.endpoint;
        var topic = parentElements.dataset.topic;
        new Vue({
            el: '#jsNewsListGridContainer' + i,
            data () {
                return {
                    endpointurl: endpointurlhref,
                    topic: topic
                }
            },
            //pass the template to the root component
            template: '<App :endpointurl="endpointurl" :topic="topic"/>',
            components: { App },
        })
    }
}

  1. This is the file

<template>
 <div>
  <ProjectsContainer :endpointurl="endpointurl" :topic="topic"/>
 </div>
</template>

<script>
import ProjectsContainer from '@/components/ProjectsContainer';
export default {
    name: 'App',
    components: {
        ProjectsContainer,
    },
    props: {
        endpointurl: String,
        topic: String
    },
};
</script>

3.

    <div class="tab-content" id="pills-tabContent">
      <div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
        <div id="jsnewslisting" class="initializeNewsList initializeNewsListContainer" ref="initializeNewsList"
          data-label-sortby="sortby" data-label-results="results" data-label-no-result-found="no results found"
          data-label-see-what-possible="see whats possible" data-label-try-to-change-filter="try to change filter"
          data-endpoint="https://5fca1f2c3c1c220016441bd2.mockapi.io/projects/newsroom" data-topic="newsroom/topic/innovation">
            <!--/*     endpoint: data-endpoint + .getNewsList.html */-->
            <!--/*     Parameters: */-->
            <!--/*     page (current page in results),topic, type, sortBy  */-->
            <!--/*     alwasy send the parameter "topic" example: endpoint?topic="newsroom/topic/innovation" */-->
            <!--/*     Muti-value params have their values separated by :  */-->
            <!--/*     codes are better example type=news:case:testimonial */ -->

          <div class="newsRoom"></div>
        </div>



      </div>
      <div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">
        <div id="jsnewslisting" class="initializeNewsList initializeNewsListContainer" ref="initializeNewsList"
          data-label-sortby="sortby" data-label-results="results" data-label-no-result-found="no results found"
          data-label-see-what-possible="see whats possible" data-label-try-to-change-filter="try to change filter"
          data-endpoint="https://5fca1f2c3c1c220016441bd2.mockapi.io/projects/newsroom1" data-topic="newsroom/topics/inspiration">
            <!--/*     endpoint: data-endpoint + .getNewsList.html */-->
            <!--/*     Parameters: */-->
            <!--/*     page (current page in results),topic, type, sortBy  */-->
            <!--/*     alwasy send the parameter "topic" example: endpoint?topic="newsroom/topic/inspiration" */-->
            <!--/*     Muti-value params have their values separated by :  */-->
            <!--/*     codes are better example type=news:case:testimonial */ -->
          <div class="newsRoom"></div>
        </div>
      </div>
      <div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab">

        <div id="jsnewslisting" class="initializeNewsList initializeNewsListContainer" ref="initializeNewsList"
          data-label-sortby="sortby" data-label-results="results" data-label-no-result-found="no results found"
          data-label-see-what-possible="see whats possible" data-label-try-to-change-filter="try to change filter"
          data-endpoint="https://5fca1f2c3c1c220016441bd2.mockapi.io/projects/newsroom2" data-topic="newsroom/topics/sustainability">
            <!--/*     endpoint: data-endpoint + .getNewsList.html */-->
            <!--/*     Parameters: */-->
            <!--/*     page (current page in results),topic, type, sortBy  */-->
            <!--/*     alwasy send the parameter "topic" example: endpoint?topic="newsroom/topic/sustainability" */-->
            <!--/*     Muti-value params have their values separated by :  */-->
            <!--/*     codes are better example type=news:case:testimonial */ -->

          <div class="newsRoom"></div>
        </div>
      </div>
    </div>

With three components set to be created, I noticed during debugging that only one prop's data was properly seeded while the other two were not. Is there a way to create components without using new Vue() in main.js? I hope someone can help me out. Thank you!

Answer №1

It appears that you are utilizing the (checkbox group) tags which may pose a problem.

<div class="form-check-input-button-wrapper" v-for="(value, index) in currentSearchedValues"  v-bind:key="index">
 <input
  type="checkbox"
  class="form-check-input-button"
  :name="value.name"
  :id="value.name.replace(' ','_')+baseURL.slice(baseURL.length - 3, baseURL.length)"
  :value="value.code"
  :checked="value.selected"
  v-model.lazy="selectedValues"
 >
 <label
  :for="value.name.replace(' ','_')+baseURL.slice(baseURL.length - 3, baseURL.length)"
  :class="{ 'form-check-label-button active' : value.selected , 'form-check-label-buton' : !value.selected }"
 >
  {{
  value.name
  }}
 </label>
</div>

Please ensure that the label :for and :id values are unique and identical to each other. Kindly notify me once you have completed this task. Thank you.

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

Removing the brackets from a nested array: A simple guide

Hello everyone! I need some assistance with removing the brackets and separating each data from a nested array. Here is the code I am working with: <template> <v-data-table :headers="headers" :items="teams" > ...

Continue running web AJAX request in Android browser while it is minimized

I need help with my AJAX call var tid = setInterval(mycode, 2000); function mycode() { $.ajax({ url:'/ajx.php', type: "GET", success: function (data) { }, ...

How can I create spacing between squares in an HTML div element?

Currently, I am working on my project using Laravel 5. I retrieve some integer values from a database and use them to create square divs in HTML. Below is the current output of my work. https://i.stack.imgur.com/sy2ru.png You may notice that there is spa ...

Accessing the parent div in an Ajax success function

I am looking for a solution to hide a parent div when a link is clicked and an ajax call is successfully made. I have tried placing the hide() function within the success part of the ajax call, but it seems to not work: $('.mylink').click(functi ...

Converting JSON-style data into a string with the power of node mysql

Just a quick note - I'm a total newbie in the world of web development, so I might be missing an obvious solution here. My challenge is to insert a dataset into a MySQL database using nodejs/expressjs/mysql. I've managed to establish a connecti ...

Implementing AJAX functionality to dynamically show a message on a webpage following an HTTP POST request

After submitting the form, I want to remain on the current page and show a message indicating whether the submission was successful or not. The HTTP POST request is processed like this: app.post('/insertdb', function(request, response) { // in ...

Are there any benefits to utilizing the Mantra.js architectural framework?

I have found that integrating Meteor.js into a Mantra.js architecture works seamlessly. However, I am questioning the advantages of using it since it seems to slow down the running of my requests. For example, when making a dummy request in GraphQL (such ...

In the dragstart event handler, event.dataTransfer and event.originalEvent will consistently be null

I have been working on developing drag and drop directives for angularJS by referencing this informative post: However, I am facing an issue where the dataTransfer and originalEvent are consistently null within the dragstart event handler, preventing me f ...

Storing objects in localStorage using VueJS

Is there a way to send all theme configuration settings as objects instead of recording them one by one? Can you provide an example if possible? Also, how do I set it on the store? I'm new to storage management so kindly provide guidance accordingly. ...

VueJS error: Trying to access properties of undefined object ('$refs') is unsuccessful

Parent Component: ... <v-stepper-step :rules="[()=>isValid(1)]" > MyStep </v-stepper-step> <v-stepper-content> <Mytag ref="MyReference" /> </v-stepper-content> ... methods: { isValid(number){ ...

Javascript, removeFromString

I'm currently working on a JavaScript function that takes in two strings. The first string is any sentence provided by the user, and the second string consists of letters to be removed from the original sentence. My approach involves converting both s ...

Automatically save user input in form fields with the help of jQuery and AJAX technology

I'm working on a form that has various input fields, and I need the data entered by the user to be automatically stored in the database every minute. After the user submits the request, it will be processed in a struts file where database interactions ...

What is the best way to apply dynamic wrapping of a substring with a component in Vue.js?

My Objective My goal is to take a user input string and render it with specific substrings wrapped in a component. Specifically, I am looking to identify dates within the string using a regex pattern and then wrap these dates in a Vuetify chip. Progress ...

Exploring the iteration process of a JavaScript array with Node-API

Currently, I am in the process of developing a Node.js addon utilizing Node-API. My algorithm takes a Javascript array as input, processes it within the addon, and then returns the result. For implementing any logic on the array, I need to iterate through ...

The Vue3 web components were unable to apply inline styles because of Content Security Policy restrictions

I recently developed a web component with a .ce.vue extension following the guidelines outlined here: https://vuejs.org/guide/extras/web-components.html#building-custom-elements-with-vue. By doing so, my styles were automatically inlined within the shadow ...

Regularly updating a book's interactive pages with turn.js technology

I experimented with generating dynamic content in turn.js using the sample provided here. This is an excerpt of the code I have written: <body> <div id="paper"> </div> </body> <script type="text/javascript"> $(win ...

Vue and Summernote issue: Model content doesn't display in form when loaded from database

I am having an issue with my form that uses the Summernote wysiwyg editor multiple times. When I fill out the form, everything works correctly - the model is updated, content is displayed, and the data is saved to the database. However, when I try to edit ...

Is it possible to incorporate async await with SetState in React?

Is there a way to properly setState when needing async/await data inside it? I know it's not recommended, but I'm struggling with getting data before setting the state. Any suggestions? codesanbox: https://codesandbox.io/s/infallible-mendeleev-6 ...

How to Redirect a Webpage to the Same Tab in ASP.NET

I am currently using an asp.net hyperlink control to direct users to a web URL when the hyperlink is clicked. My goal is for the user to open a new tab, rather than a new window, when they click the hyperlink. If the user clicks the link again, I want th ...

What improvements can be made to optimize this SQL query and eliminate the need for an additional AND statement at the end

I am working on dynamically constructing a SQL query, such as: "SELECT * FROM TABLE WHERE A = B AND C = D AND E = F" Is there a more efficient way to construct this SQL query without adding an extra AND at the end? Here is my current code snippet: le ...