How to Add a Foreign Component to Your Vue Application

I'm trying to utilize a NPM package called vue-simple-spinner in my Vue CLI webpack application, but I keep encountering this error message:

Unknown custom element: <vue-simple-spinner> - have you registered the component correctly? For recursive components, make sure to provide the "name" option.

The documentation states: https://i.sstatic.net/2dAAr.png

Following that, I added the following code in my main.js file:

import Vue from 'vue'
import App from './App'
import router from './router'
import Spinner from 'vue-simple-spinner'

import BootstrapVue from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

Vue.config.productionTip = false
Vue.use(BootstrapVue)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {
    App,
    Spinner
  },
  template: '<App/>'
})

Further instructions from the documentation say:

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

I have included the

<vue-simple-spinner></view-simple-spinner>
tags but I am unsure of where or how to include the JavaScript scripts. I tried including them in the template (which resulted in an error) and also attempted importing the component using
import Spinner from 'vue-simple-spinner'
but both approaches are still triggering the Unknown custom element error.

How can I properly include the scripts and/or register the component?

This is the complete content of my Vue app file:

<template>
  <div id="app" class="container">
    <div>
      <h1>Market Price Spreads</h1>
      <button type="button" class="btn btn-primary" v-on:click="loadMarkets()">Refresh Markets</button>
      <vue-simple-spinner></vue-simple-spinner>
    </div>
    <div class="main-table">
      <table class="table table-striped table-bordered">
        <thead>
          <tr>
            <th>Market</th>
            <th>Poloniex</th>
            <th>Bittrex</th>
            <th>Spread</th>
          </tr>
        </thead>
          <tbody>
            <tr v-for="market in markets">
              <td>{{ market[0] }}</td>
              <td>{{ market[1] | round(6) }}</td>
              <td>{{ market[2] | round(6)}}</td>
              <td>{{ market[3] | round(2)}} %</td>
            </tr>
        </tbody>
      </table>
    </div>
  </div>

</template>

<script>
  /* eslint-disable */

  import loadDataMixin from './components/mixins/loadDataMixin'

  export default {
    name: 'App',
    mixins: [loadDataMixin],
    filters: {
      round: function(number, places) {
        return number.toFixed(places)
      }
    },
  }
</script>

<style>
  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: #2c3e50;
    margin-top: 60px;
  }
  
  .main-table {
    margin-top: 20px;
  }
</style>

Answer №1

parts: {
  Card
}

can also be written as

parts: {
  Card: Card
}

this will register your component as <card>. Give it a try:

parts: {
  'custom-card': Card
}

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

This element is not compatible for use as a JSX component

I have created a React component which looks like this import React from 'react'; import { ECOTileSummary } from './ECOTileSummary'; import { TileSummary } from './TileSummary'; interface SuperTileSummaryProps { date?: s ...

Hook on UI-Router that triggers after the template has been retrieved and added to the DOM

We are faced with the challenge of supporting a legacy module that requires synchronous code to run after templates have been fetched and attached to the DOM. As we transition from our custom router to UI-Router, we have successfully resolved the route an ...

Resetting a Material UI search filter TextField back to its initial state after clearing it

Unleashing the power of ReactJS alongside Material UI has been a journey of ups and downs for me. While I managed to create a versatile search filter component for my data tables that worked like a charm, I now find myself at a crossroads. My new goal is t ...

Leveraging Vue.js to showcase API information through attribute binding

My application is designed to allow a user to select a Person, and then Vue makes an API call for that user's posts. Each post has its own set of comments sourced from here. You can view the codepen here Here is my HTML structure: <script src="h ...

Uniquely tag an uploaded file

My code for uploading files is as follows: var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.open("POST", requestUrl, true); xhr.send(f); I want to draw your attention to the fact that I have attached a l ...

What is the most effective method for daily column reset with a large user base?

While working on my current project in Laravel, I've come across the need to implement a feature that requires a column reset for all users every day. With potentially hundreds or thousands of users in this project, I'm concerned about potential ...

What is the most effective method for the server to communicate with a web client through message delivery?

If you have any links to articles related to this topic, please share them as I may not know the exact terminology to search for. I am interested in understanding how a web application can facilitate server-to-client communications. The internet was not o ...

What is the best way to pass the value from one JavaScript file to another in the ViewModels and main JavaScript file?

https://i.sstatic.net/pzFAS.jpg Within the login.js file, a REST API is returning specific values that need to be utilized in the Dashboard.html file. However, the values are not being retrieved successfully in the dashboard.js file. A similar requiremen ...

How can you utilize a previously opened window from another page in JavaScript?

One of my challenges involves managing windows in a JavaScript environment. When I open a child window using window.open("http://foobar","name"), it reuses the same window when opened with the same name, which is exactly what I want. However, if the origi ...

Display previous messages in React JS chat when scrolling upwards

https://i.sstatic.net/mcJUp.png I am currently working on a chat application, as depicted in the image. Once the chat is initiated, it automatically scrolls down to display the most recent messages. My goal is to implement a feature where when a user sc ...

Click on a table cell in Vue to display its corresponding data in a modal

I have successfully implemented a modal in my Vue component that works well with static text inside it, confirming its functionality. However, when attempting to pass data from the table cell that is being clicked into the modal, I encountered an error st ...

Supplying information to my ejs template while redirecting

I am currently working on a feature that involves sending data from the login page to the home page when the user is redirected. This data will then be used in the home EJS file. Below is the code snippet I have implemented: module.exports = functio ...

What is the best way to retrieve ul li values using AngularJS?

I am looking to extract the content of li elements within a ul element in an AngularJS controller and save them into an array. Sample HTML Code: <ul id="list" my-directive> <li>A</li> <li>B</li> <li>C ...

What is the best way to extract data from a JSON object in JavaScript?

let result = JSON.parse(data.d); The current code doesn't seem to be working.. Here is the structure of my JSON object: [{"ItemId":1,"ItemName":"Sizzler"},{"ItemId":2,"ItemName":"Starter"},{"ItemId":3,"ItemName":"Salad"}] Any suggestions on how I ...

Is it possible to extract the version_name using the version_code of an android package?

Is it possible to retrieve the version_name by using the version_code of an Android package? For instance: 'com.nianticlabs.pokemongo' version_code: 2017121800 => version_name: 0.87.5 I'm looking for a function that can accomplish th ...

Ways to isolate and limit the application of CSS in React and Gatsby to specific pages instead of having it affect the global scope

At the moment, I'm working on integrating a keen-slider library(https://www.npmjs.com/package/keen-slider). To install it, we have to include import 'keen-slider/keen-slider.min.css'. This essentially adds the CSS globally to our project. Ho ...

Bootstrap Modal for WooCommerce

I'm facing an issue while trying to create a modal window using woocommerce variables ($product). The problem lies in the placement of my modal and accessing the correct product id. Here is the code snippet I've been working on. Unfortunately, i ...

Struggling to make vue-i18n function properly with nuxt generate?

In an effort to enhance my skills, I am creating a small Nuxt project from scratch. While the project runs smoothly on the local server, I have encountered an issue with the language switcher not updating the translation fields when using nuxt generate. U ...

The Vue background container fails to display the image

I'm having trouble setting an image as the background for a div element. Despite my numerous attempts, I haven't been able to make it work. No results are displayed and there are no error messages to indicate what went wrong. I recently stumble ...

CSS and JavaScript dropdown malfunctioning due to a position swap in internal CSS

This example demonstrates functionality .c1 { background-color:red; position:relative; } .c2 { background-color:blue; position:absolute; height:50px; width:100px; display:none;} .show { display:block; } <body> <button ...