Error encountered while using VueJS: The Register component was not recognized as a

Encountering issues with the registration component in VueJS. I acquired the component from https://github.com/wanxe/vue-button-spinner via npm install. Subsequently, I integrated the code into my Laravel 5.5 app.js file.

The contents of my app.js:

require('./bootstrap');

window.Vue = require('vue');
import Spinner from './components/Spinner.vue'

window.onload = function () {

    Vue.component('button-spinner', require('./components/Spinner.vue'));
    var vw = new Vue({
        el: '#app',
        components: {
            'button-spinner': Spinner
        }
    });

};

Snippet of Spinner.vue code:

<script>
    import VueButtonSpinner from 'vue-button-spinner';

    console.log('Test');

    export default {
        name: 'events-form',
        data() {
            return {
                isLoading: false,
                status: '',
            }
        },
        components: {
            VueButtonSpinner
        },
        methods: {
            onSubmit() {
                this.isLoading = true
                $someRequest('/url', 'GET')
                    .then(response => {
                        this.isLoading = false
                        this.status = true // or success
                        setTimeout(() => { this.status = '' }, 2000) // to clear the status :)
                    })
                    .catch(error => {
                        console.error(error)
                        this.isLoading = false
                        this.status = false //or error
                    })
            }
        },
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

Following the integration, I executed npm run dev and included the necessary HTML code.

<div id="app">
 <button-spinner
                        :isLoading="isLoading"
                        :disabled="isLoading"
                        :status="status">
                <input type="submit" :disabled="submitted" :class="{ 'disabled': submitted == true }" @click="submit('register', $event)"
                       v-model="registerSubmit" id="registerSubmit" style="width: 100%; height: 40px">
                </button-spinner>

</div>
<script src="{{URL::asset('js/app.js')}}"></script>

However, upon testing, the component failed to work as expected. The console output indicated a

Unknown custom element: <button-spinner>
error.

https://i.sstatic.net/Uxk0l.png

EDIT:

After removing window.onload = function () from app.js, the

console.log('Component mounted.')
ran successfully but resulted in a further error regarding template/render definition within Spinner:
[Vue warn]: Failed to mount component: template or render function not defined.found in---> <ButtonSpinner> at resources/assets/js/components/Spinner.vue<Root>
.

An additional issue emerged after excluding the window.onload. This was exacerbated by linking extra JS files in the HTML.

<script src="{{URL::asset('js/login.js')}}"></script>
<script src="{{URL::asset('js/register.js')}}"></script>

These scripts, which utilize VueJS, generated numerous errors.

https://i.sstatic.net/hTOaA.png

While everything functioned seamlessly with window.onload, the question arises whether these files should be incorporated directly into app.js? For instance, should the register.js file be included like so: https://pastebin.com/0uHxRcN9.

Revised app.js content:

window.Vue = require('vue');


require('./bootstrap');

import Spinner from './components/Spinner.vue'

    require('./register');
    require('./login');
   new Vue({
        el: '#app',
        components: {
            'button-spinner': Spinner
        }
    });

Answer №1

You have implemented the component in two different ways

Please remove the following section:

Vue.component('button-spinner', require('./components/Spinner.vue'));

Make sure to make the necessary changes here:

components: {
    buttonSpinner: Spinner
}

Do not include HTML inside the component like input, please remove it.

<input type="submit" :disabled="submitted" ....

To pass parameters to child components, use props:

props = ["isLoading","disabled","status"]

Define these properties in the main component as well:

isLoading: false,
status: '',

Answer №2

When you're working with Vue, it's important to note that ComponentName gets converted to component-name when registering a component inline. To solve your issue, simply update your 'import alias' like so: ButtonSpinner

import ButtonSpinner from './components/Spinner.vue'

// In the components property 
components: {
   ButtonSpinner
}

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

Consistently shifting the Aframe camera towards the focal point

Is there a way to continuously adjust the view of my Aframe scene based on the current viewing direction? It seems like there are two key components needed for this: (1) obtaining the current viewing direction in the correct format, and (2) creating and u ...

Leveraging v-radio within v-tab

Is there a way to incorporate the v-radio component within a v-tab and have it automatically selected when the tab is chosen? The challenge I'm facing is that I am unsure of how to individually select a single v-radio without using v-radio-group, as ...

Can you extract debugging details from an ajax preflight inquiry?

I am currently working on a JavaScript project that involves making an AJAX request. However, I am encountering issues with the preflight OPTIONS call for this request failing. To provide some transparency to the user, I would like to display debug infor ...

What sets apart the npm packages @types/express and express?

Can't decide whether to use @types/express or express for building a node server? Take a look at the code snippet below: 'use strict'; const express = require('express'); const http = require('http'); const path = requir ...

Encountering an error while configuring webpack with ReactJS: Unexpected token found while

I'm attempting to update the state of all elements within an array in ReactJS, as illustrated below. As a newbie to this application development, it's challenging for me to identify the mistake in my code. closeState(){ this.state.itemList.f ...

Making changes to a database model (updating or replacing)

When making changes to a model in the database, is it more efficient to only update a specific field or replace all objects at the same level with that field? ...

jQuery .click() only triggering upon page load

I've been searching all over the place and I just can't seem to find a solution to my specific situation. But here's what I'm dealing with: Instead of using inline HTML onclick, I'm trying to use jQuery click() like this $(docume ...

Showing VUE Content Delivery Network

Unable to render v-for with CDN in Vue.js const Gallery = { template: '{{$t('gallery')}} <img :class="[[item.class]]" v-for="(item, index) in carousel" :src="[[item.img]]" alt="img" />' } c ...

Validation issue with Reactive Forms not functioning as expected

My latest project involves a user signup component that I created from scratch import { Component } from '@angular/core'; import {UserManagementService} from '../user-management.service'; import {User} from "../user"; import {FormBuild ...

Getting rid of the scrollbar in Internet Explorer

Instead of just removing the scrollbar, I want to ensure that scrolling capabilities remain intact. This is important because I want to create a 'slide show' effect on the website where users can click 'next' and scroll through content ...

React Native: LogBox now including all warnings

Looking for a way to use LogBox to filter out specific log messages, but despite my attempts to ignore them, they still show up in the console... "react-native": "0.68.2", In my main file (index.js), this is how I've tried to impl ...

Something went wrong with the API: an error occurred where headers were sent to the client before they could be set

Recently, I've encountered an issue where users are facing errors during registration or login. The error message pops up occasionally and here is a screenshot of it: https://i.sstatic.net/zum1u.png Below is the code snippet that I'm using: htt ...

Emscripten WebAssembly: Issue with Exporting Class "Import #13 module="GOT.func" error: the module does not exist as an object or function"

Exploring the potential of WebAssembly in a project as an importable function module, I decided to dive into using C++ with Emscripten. Implementing functions was smooth sailing, but running into obstacles when it comes to classes. My goal is to expose and ...

Processing a JSON array of objects in AngularJS

When using Angular's fromJson function to parse a JSON string, I encountered an issue. If the JSON is a simple array like "[1, 2]", the code works fine. However, I need to work with an array of dictionaries instead. var str = "[{'title' ...

AngularJS $log - display line numbers

When using angularjs $log in chrome, it displays the line as: angular.js:9037. I'm looking to have the line number where I actually call this method shown instead. (Displaying my js name and the correct line). Is there a way to achieve this since Angu ...

What are the ideal scenarios for implementing React.Fragments?

Today I discovered React Fragments and their benefits. I learned that fragments are more efficient by reducing the number of tree nodes and improving cleanliness in the inspector. However, is there still a need to use div tags as containers in React compo ...

The functionality of sending form data via Express.js router is restricted

In my current project, I am developing a basic CRUD functionality in express. My goal is to utilize the express.Router() to transmit form data via the HTTP POST method. The form structure on the browser appears as follows: form.png The process was flawle ...

Stop objects from shifting while easily applying a border

I have a code that adds a red border around elements when you mouseover them and removes it when you mouseout. However, the elements jump around when the border is added because it changes their dimensions. Is there a way to stop this jumping behavior? ...

Setting up global Axios configuration with authentication in NuxtJS using VueJS

In my quest to configure Axios globally with authentication in NuxtJS - VueJS (primarily NUXTJS), I am facing a challenge. What I aim for is pretty straightforward: If a user is logged in and has a token in $store, I want Axios to use this token. If the u ...

What is the best way to reference a const from a different class in React?

I'm relatively new to ReactJS, specifically using NextJS. In my project, I have two files - index.js and welcome.js In index.js, I've added Welcome as a component, along with a const called hideWelcome to hide the component and perform some acti ...