Develop a Vue app specifically designed as a component to seamlessly integrate with another project's Vue router

I am working on developing a Vue app that can be used as a component for other Vue projects in the app's Vue router. To start, here is my simple project structure:

|-- my-app
    |-- lib
        |-- my-app-component <-- folder copied from (my-app-component's dist)
    |-- App.vue
    |-- app.js
    |-- package.json



|-- my-app-component
    |-- dist
    |-- App.vue
    |-- app.js
    |-- package.json

Here are the idea and steps I am trying to implement:

  1. Build my-app-component as a reusable component. The code in my-app-component->app.js is
import MyCustomElement from './App'

export {
   MyCustomElement
}
  1. Copy the dist folder to the lib folder of my-app. This is just a temporary solution and will be improved using Lerna and yarn workspaces once I solve the current issue.
  2. Import my-app-component from lib in my-app's lib. The code in my-app -> app.js is,
import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import MyAppComponent from '@lib/my-app-component'

const routes = [
  {
    name: 'MyAppComponent',
    path: '/',
    component: MyAppComponent
  }
]

const router = new VueRouter({
  routes
})
new Vue({
  el: '#app',
  router,
  components: {
    App
  },
  template: '<App/>'
})

Despite following these steps, I am struggling to successfully import the component. I am building my component using the vue-cli-service build command.

Answer №1

Discovered the solution right here...

Lately, I've been finding answers to my own questions. Is stack overflow still active?

The Method:

  1. Begin with
vue-cli-service build --target lib --name dummylib src/main.js
  1. Include main in package.json
"main": "./dist/dummylib.common.js",
  1. In the main app, add the component using
yarn add ../dummylib
  1. Import and utilize the component
import DummyButton from 'dummylib'
export default {
  name: 'app',
  components: {
    'dummy-button' : DummyButton
  }
}

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

Executing several asynchronous functions in Angular 2

I am currently developing a mobile app and focusing on authentication. In order to display data to the user on my home page, I need to connect to various endpoints on an API that I have created. Although all endpoints return the correct data when tested i ...

Something is not quite right when the page is loading in a Ruby on Rails application

In the process of developing a wiki clone, I am faced with an issue involving JavaScript. When I navigate to a specific page by clicking on a link, the JavaScript does not function properly until I refresh the page. The JavaScript aspect mainly involves an ...

Using require to access an Immediately Invoked Function Expression variable from another file in Node.js

File 1 - Monitor.js var MONITOR = (function () { // Code for Monitoring return { doThing: function() { doThing(); } }; })(); File 2 - Test.js var monitor = require('../public/js/monitor.js'); I am trying to access the doThing() funct ...

Is adding ng-click in a template counterproductive to the concept of MV* architecture?

When working with AngularJS, you may come across instances where the ng-click handler is directly connected to an HTML element like <a> or <button>. Take for example the snippet below (borrowed from an Angular homepage sample), where the click ...

Using Laravel to find records within a specific date range

Currently, I am able to search for an article and a specific date. How can I expand this search functionality to include searching for articles between two specific dates? Assuming criterion 1 is the name field and criterion is created_at, how can criteri ...

How do I retrieve an index value from an array in GraphQL?

I am seeking a solution for obtaining the index of an array item that is not returned by downstream response. Let's consider my schema: schema: type Cart { items: [Item] } type Item { name: String index: Int } When the data comes in, it lo ...

Error rendering Vue nested route

I am encountering an issue with a nested route that is not rendering and instead throwing an error: vue.esm.js?efeb:571 [Vue warn]: Failed to mount component: template or render function not defined. found in ---> <BlEditOrder> <BlOrd ...

Detecting collisions in Three.js

I seem to be overlooking something quite fundamental, as I can't seem to find a solution in the documentation or any other working code examples. I am currently creating a basic museum using THREE.js libraries. While most of it is set up, I need to im ...

Fixing the 'window is not defined' Error in Node JS through Command Line

Trying to incorporate Angular JS using 'require' in my code snippet: var ang = require('angular'); However, encountering an error: ReferenceError: window is not defined I am aware that the window object is not defined in the Node co ...

Finding the filename using the event object in JavaScript: A step-by-step guide

Picture this scenario: an HTML file named page1.html includes a script tag for base.js. Within base.js (an external JavaScript file), I assign an onclick listener to a button that exists in page1.html. This base.js file is also included in script tags on o ...

Setting Metadata Dynamically in Vue Router

Currently, I have a Single Page Application (SPA) built with Vue and Vue Router. The setup mimics an iOS app where the title in the navigation bar changes as you navigate deeper into the views. Right now, the titles are hardcoded in the routes.js file, but ...

Employing ExpressJS on the server side and JQuery on the client side for handling static links

Recently delved into the world of jQuery and node.js, and everything was smooth sailing until I hit a roadblock. Despite my best efforts to search online, I couldn't find a solution to my problem. It seems like a simple issue, but I just can't fi ...

Upon loading the page, a forward slash is automatically added to the end of the URL

My website has multiple pages of content, but I've noticed a strange issue with the URLs. When I navigate to example.com/guides, a forward slash is automatically added to the address bar, resulting in example.com/guides/. Surprisingly, the page still ...

Verifying a user's initial visit status using COOKIES in a Servlet

Is there a method to determine if a user is visiting a page for the first time using SERVLET and cookies, without utilizing sessions? I understand how to accomplish this with sessions, but I am specifically looking for a solution that involves only cooki ...

Encountering an issue with inability to resolve the 'react-navigation-stack' module. Still seeking a solution to this problem

Having trouble with my react navigation in react native. I've already added npm react-navigation-stack and also npm install --save react-native-gesture-handler react-native-reanimated react-native-screens. The error message I'm getting is: Unab ...

Connecting Arrays within Arrays in VUE and VUEX: A Comprehensive Guide

In the process of developing a VUE(X) application that involves multiple arrays. state: { triads: [{ people: [], places: [], equipment: [] }] }, I aim to create a user interface with three lists, each containing an input field for adding ...

Acquire a numerical value from a text source and increment it by one using Jquery

I have a simple task of extracting a single number from a particular div. Once obtained, I intend to increment the number by one. However, despite successfully retrieving the number, my attempts to add one to it are not working as expected. For example: ...

Adjust the position if the height exceeds 100 pixels

Can someone help with this code issue? $(document).ready(function () { if ($('.pi-img').height() > 100) { $(this).css('top' , '30%'); console.log('yeah'); } }); I am encountering difficu ...

What is the best way to transfer an integer from my main application to a separate JavaScript file?

Currently, I am developing a complex code using React Bootstrap and focusing on creating a Dropdown list that fetches data from the backend database. <Dropdown> <Dropdown.Toggle variant="success" id="dropdown-basic"></D ...

What are the connections between objects in ReactJS?

I have an array containing objects, and I want to extract a specific value from another array by using the key inside it as a search parameter. Specifically, I need to retrieve the name of an item based on its ID. The primary array: this.setState({ offer ...