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

Display tooltip information based on dynamic content

Can the q-tooltip text be loaded dynamically? Which property should be used for this purpose? In my scenario, which property should replace :value (please note that this is just a demonstration and not an actual property of q-tooltip)? <q-item-sectio ...

Sending axios post requests in succession in Vue.js

I need to execute two post requests, where the second one should only be triggered after the first one receives a response. I tried using async/await but didn't find a satisfactory solution. let changed = false; if(//condition){ changed = true; ...

Directly transfer image to Cloudinary without creating a local file

I have integrated jdenticon to create user avatars upon signup in a node/express app. When working locally, I follow these steps: Create identicon using jdenticon Save the file on my local machine Upload the local file to cloudinary Here is a snippet o ...

Focusing on the combination of Phonegap, Angular JS, and Onsen for app development

We are working on developing an app using PhoneGap, Angular JS, and Onsen. One issue we are facing is that we are unable to center the header in a modal. The code snippet is provided below: <ons-modal var="modalVariable"> <ons-navigator var"de ...

Is it possible to reverse the use of JQuery's .each() function without any additional plugins or modifications?

Similar Question: Reversing JQuery .each() Is there a better approach to using .each() in reverse? Currently, I am implementing it like this: var temp = []; $("#nav a").each(function() { temp.push($(this)); }); temp.reverse(); for(var i = 0; i ...

Tips on combining multiple HTML tags within a single div element

After extracting a value from an XML document using Javascript, I encountered a problem while attempting to generate multiple image tags based on that value. Despite my attempt with a for loop, only one image was being displayed. for(i=0; i<red; i++){ ...

I'm trying to display hidden forms on a webpage when a button is clicked using the DojoToolkit, but I'm having trouble figuring out what's going wrong with my code

Currently, I am trying to grasp the concepts of Dojotoolkit and my objective is to display a form when a button is clicked. Upon reviewing other examples, my code seems correct to me; however, there appears to be something crucial that I am overlooking but ...

A guide on how to perform a PUT or DELETE operation for Azure Table Storage using Node.js

I've been faced with a challenge in my project where I aim to create basic CRUD functionality for Azure Table Storage. However, I'm encountering difficulties in generating a valid SharedKeyLite signature. While I can successfully generate valid ...

Guide to uploading a JavaScript File object to Cloudinary via the node.js API

After researching various options, I decided to use cloudinary for uploading a file to an image server from my node js api. I successfully installed the npm package for cloudinary and implemented the code based on their api documentation Below is the fun ...

invoking a function by utilizing nested controllers

Struggling with nested controllers, the main goal of this code is to link data extracted from a .json file to another function or file. .html file: <div ng-app="myApp" ng-controller="GetCtrl" > <li ng-controller="ChannelCtrl" ng-repeat="x in ...

Placeholder variable not specified in radio buttons

I am currently facing challenges applying validations to radio buttons in Angular. Normally, I create a #templateRefVariable on the input for other input types, which allows me to access the NgControl and use properties like touched. My goal is to set the ...

Integration of PHP and MySQL with PayPal can be challenging, especially when the PayPal button fails to function unless the amount is

When I initially set the amount value, clicking the "Pay with PayPal" button does not trigger any action. However, if I manually adjust the amount, the PayPal button starts functioning properly. This is how the input field appears: <input name="am ...

What steps can I take to ensure my CSS component remains unaffected by the global CSS styles?

My navbar component is not displaying the styles correctly as intended. I have a Navbar.module.css file to style it, but after using next-auth for social login, only the buttons remain unstyled while everything else gets styled. The code snippet for impor ...

Issue: Request from a different origin blocked

I encountered an issue while working on a web project using the PlanGrid API. I am receiving a cross-domain request block error. var apiKey="API KEY"; var password="PASSWORD"; $.ajax({ url: "https://io.plangrid.com/projects", xhrFields: { ...

Angular2: Leveraging click events to manage CSS classes on elements

I am currently developing a web app using Angular 2. I'm facing an issue where the active element should receive an extra CSS class when clicked, but adding the ":active" CSS attribute with a custom class doesn't work as expected. The ":focus" pr ...

Is it possible to include a JavaScript script in a Laravel Blade file?

I have an Auth module from nwidart/laravel-Module. I am trying to include a script file in the Modules\Auth\Resources\views\layouts\app.blade.php file, like this: <body> ...... ... <!-- Scripts --> <script s ...

Netlify Lambda function with Expressjs generates a fresh session for each incoming request

Good Evening, After successfully running my Expressjs API locally without utilizing lambda functions, I encountered an issue where every request created a new session once the lambda function was introduced. Below is the implementation of server.js and Das ...

Using React's useEffect to implement a mousedown event listener

I created a modal that automatically closes when the user clicks outside of it. method one - involves passing isModalOpened to update the state only if the modal is currently open. const [isModalOpened, toggleModal] = useState(false); const ref = useRef(n ...

Creating a combinational chart with varying data values using Echarts in Vue.js

In my VueJS application, I am facing a challenge while using Echarts to visualize data. The issue arises when I try to create an echart with multiple series that have different numbers of values in their data objects. EChart requires all series objects to ...

html interactive/expandable tree

I've come across this code which generates an HTML tree, but I'm facing an issue where the tree expands every time I refresh the page. What I want to achieve is to have certain branches expanded and others collapsed when the page is opened, depe ...