Can components be nested within other components using http-vue-loader?

Trying to incorporate Vue components within components without utilizing webpack for practical reasons is my current challenge. I have opted to use http-vue-loader for loading the vue files into my project.

Thus far, I have successfully created vue files and embedded them into my HTML as shown below:

main.js

new Vue({
  el: '#app-shop',
  components: {
    'comp-products': httpVueLoader('components/comp-products.vue'),
    'comp-shop': httpVueLoader('components/comp-shop.vue')
  },
});

comp.shop.vue

<script>
    module.exports =  {
        props:{
            quantity: {
            type: Number
            }
        }
    }
</script>

comp.products.vue

<template>
    <div id="products">
        <div class="productsItemContainer" v-for="product in products">
            <div class="productsItem">
                <div class="">
                    <div class="mkcenter" style="position:relative">
                        <a class="item">
                            <img class="productImg" width="120px" height="120px" v-bind:src="'assets/products/' + product.image">
                            <div class="floating ui red label" v-if="product.new">NEW</div>
                        </a>
                    </div>
                </div>
                <div class="productItemName" >
                    <a>{{ product.name }}</a>
                </div>
                <div class="mkdivider mkcenter"></div>
                <div class="productItemPrice" >
                    <a>€ {{ product.unit_price }}</a>
                </div>
                <div v-on:click="addToCart" class="mkcenter">
                    <div class="ui vertical animated basic button" tabindex="0">
                        <div class="hidden content">Koop</div>
                        <div class="visible content">
                            <i class="shop icon"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    module.exports =  {
        name: 'Products',

        data() {
            return {
                products: [],
                addToCart: function(){
                    // quantity++;
                    console.log("test")
                    console.log(quantity)                    
                }
            }

        }            
  },

        mounted() {
            axios
            .get("json/products.json")
            .then(response => {
            this.products = response.data.products;
            });
        }
    }
</script>

<style>
    #products{display:flex;flex-wrap:wrap;padding:20px}
    .productsItemContainer{padding:5px;margin:auto;text-align: center}
    .productsItem{width: 200px;padding:20px 0px 10px 0px;;border:1px solid #ddd}
    .productsItem:hover{border:1px solid #ddd;-webkit-box-shadow: 0px 0px 13px -1px rgba(0,0,0,0.13);-moz-box-shadow: 0px 0px 13px -1px rgba(0,0,0,0.13);box-shadow: 0px 0px 13px -1px rgba(0,0,0,0.13);}
    .item{width: 50%;margin: 0px}
    .productImg{transition: all .5s ease-in-out;}
    .productImg:hover{transform: scale(1.1);}
    .productItemName{text-align: center}
    .productItemName a{font: Roboto; color:#333745;font-size: 17px}
    .productItemPrice{text-align: center; padding: 5px 0 10px 0; }
    .productItemPrice a{color:red; font-size: 16px;font: Roboto; color:black; font-weight: 700}
</style>

The current setup is functioning well, but I am eager to discover a method to invoke comp.products.vue from within comp.shop.vue.

Answer №1

Inside your main.js file, include header.vue as a component:

<script>
    module.exports =  {
        props:{
            title: {
            type: String
            }
        },
        components: {
            'header': httpVueLoader('components/header.vue')
        }
    }
</script>

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

Ajax transmitting data with concealed characters

I'm trying to send data from one PHP site to another. On the first site, everything looks good. The string appears as --show="author,book,text/n However, when I check the string after receiving it on the second site, it shows --show="author,b ...

"Exploring the power of JQuery in adding new elements and accessing the newly appended

I have a code that appends some HTML to a div using JQuery like this: $("#divId").append("<div class='click' data-id='id'></div>"); and I want to access the appended div by clicking on it like so: $(".click").click(functi ...

Surprising behavior experienced with Angular alert functionality

I'm currently delving into the world of Angular and came across a puzzling issue that caught my attention. To simplify the problem, I created a concise example as the original code was considerably longer. Desired Outcome: I envision a scenario whe ...

Unable to update the information within a DIV using Python Django, as well as the webpage following a jQuery action

Exploring new ideas through the lens of two variables in an HTML template, messages and users, a series of buttons trigger a jQuery function upon being clicked. This function sends a post request to a Django server, which then returns an update to the mess ...

Having difficulty retrieving the necessary information for manipulating the DOM using Express, Ajax, and Axios

When working on DOM manipulation based on AJAX calls, I've encountered an issue where the response is being displayed on my page instead of in the console.log output. This makes it difficult for me to view the data and determine what needs to be inser ...

Using the feColorMatrix SVG filter in CSS versus applying it in JavaScript yields varied outcomes

If we want to apply an SVG filter on a canvas element, there are different ways to achieve this. According to this resource, we can apply a SVG filter to the CanvasRenderingContext2D in javascript using the following code snippet: ctx.filter = "url(#b ...

Replacing text with new content when text is stored in a separate file

After organizing all the strings from my code, I compiled them into a file named constants.ts. export class Constants { public static API_URL = '/api/'; public static CREATE_CHILD_API_URL = Constants.API_URL + '%s' + '/create- ...

Solving the puzzle of complex polymorphic object model deserialization in Java Jackson: Facing the JsonMappingException error – Unexpected token (START_OBJECT) instead

I am working with a hierarchy of objects described as follows: A B extends A C extends B D extends B E extends C F extends A and contains a reference to A The annotation for class A is defined as: @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS,include=Jso ...

Dynatree fails to consider the select feature while utilizing ajax requests

Currently, I am utilizing the dynatree plugin to exhibit a checkbox tree in multi-select mode (mode 3). Upon initializing the tree using ajax (without lazy loading), it appears that certain nodes that were initially loaded as selected are forgotten. When ...

Tips for Positioning Javascript Onclick at the Center of the Screen

Could someone please assist me with centering my JavaScript pop up on the screen? Currently, when I scroll down and activate the onclick popup, it appears at the top of the page, out of view. How can I ensure that the popup appears in the center of the scr ...

JSON parsing in C#

I'm struggling to parse JSON in c# that is structured like the example below. The code snippet I have been using is somewhat functional, but it lacks stability. (I'm also looking for guidance on how to parse JSON in Javascript, which is another ...

The occurrence of an unanticipated character '#' was found

I'm currently facing an issue while using webpack to load dependencies. Whenever I execute the npm run dev command, I encounter the following error: Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: ...

Tips on automatically adjusting the width of a div to fit the content, maintaining center alignment, and ensuring the contents float to the left

I am facing an issue with a div element that has multiple children. My goal is to have the children neatly fit to the bottom left of the grid when the window expands, utilizing the next available space efficiently. However, as the div expands with the wind ...

How is it possible for a JavaScript variable sharing the same name as a div Id to automatically pass the div?

This is just ridiculous. Provided HTML <p id = "sampleText"></p> Javascript var sampleText = "Hello World!"; Execution console.log(sampleText); // prints <p id = "sampleText"></p> How is this even possible? I ...

The error message "POST .../wp-admin/admin-ajax.php net::ERR_CONNECTION_CLOSED" appears when a WordPress AJAX request receives data that exceeds 1MB in size

When I attempt to submit a jquery ajax form from the frontend and upload a blob (a variable of string) as a .txt file to WordPress using wp_handle_upload(), everything works smoothly until the file size reaches around 1mb. At that point, an error is displa ...

I am encountering an issue where the msal-browser login process seems to be frozen at the callback

After successfully installing the msal-browser package, I am able to log in. However, I encounter an issue where the screen gets stuck at the callback URL with a code. The samples provided in the GitHub repository demonstrate returning an access token in ...

Vue warning: Issue encountered in created hook - Attempting to access property 'get' of an undefined variable is causing a TypeError

I encountered an error while using axios: [Vue warn]: Error in created hook: "TypeError: Cannot read property 'get' of undefined" export default { methods: { loadUsers(){ axios.get("api/user").then(data => ...

Assign a value to an element based on a specific attribute value

I'm working with the following element <input type="text" size="4" name="nightly" value="-1"> My goal is to update the value to 15.9 specifically when name="nightly" Here's what I've attempted so far: document.getElementsByName(&ap ...

One way to integrate social sharing buttons into your Django blog

I am currently using the django_social_share module and I am struggling to understand how to send the sharing URL for a specific blog post on social media. Here is my post_detail.html: <article> <div class="embed-responsive embed-responsive-1 ...

Searching for specific objects within a nested array in TypeScript

I have been searching for examples for a while now, but I haven't found anything similar. My understanding of the filter function is lacking, so any assistance would be greatly appreciated. The goal is to remove elements from the object where the nest ...