Is the object structure for accessing context/global properties in Vue 3 using the Composition API different when building with Vue-CLI 4 for development or production?

What causes the difference in object structure from the result of getCurrentInstance() with the Composition API between a development and production build?


This is my approach for adding globals to my Vue instance:

    export default {
      install(app) {
        const _projectFile = new ProjectFile(app);
    
        //* This will help for accessing the store in other files (plugins)
        app.config.globalProperties.$projectProperties = _projectFile;
    
        //* This will expose the store in components with this.$store
        app.provide('$projectProperties', _projectFile);
      }
    };

I am implementing this in my main.js, along with other setup (which all functions correctly).

    import App from './App.vue'; // Main Vue component
    const app = createApp(App)
    .use(projectProperties);
    app.mount('#app');

The confusion arises here.. When attempting to access my globalProperties from the setup() function in ./App.vue using the Compostion API, I notice that the object structure returned by getCurrentInstance() differs when running:

  1. vue-cli-service serve (development)
  2. vue-cli-service build (production)

./App.vue

  setup() {
    const _instance = getCurrentInstance();

    onMounted(async function() {
      // This syntax only works when using vue-cli-service serve
      const { $store, $router, $projectProperties } = _instance.ctx;

      // This syntax works for both vue-cli-service serve & build
      const { $store, $router, $projectProperties } = _instance.appContext.app.config.globalProperties;

      // Additional code not relevant to this issue

    });
  },

Hence, the following line does not work in the production build:

const { $store, $router, $projectProperties } = _instance.ctx;

I'm puzzled why getCurrentInstance().ctx references the globalProperties object with cli-service serve but fails to include globalProperties in the cli-service build environment?

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

Creating an array of choices using jQuery: A step-by-step guide

In a jQuery solution I found on Stack Overflow, there was code used to show a specific div block only when certain menu options are selected. While I'm not well-versed in jQuery, I believe the $.viewMap block could be optimized to avoid repeating part ...

Execute a jQuery function every time the class of the parent container div changes

I am seeking to trigger the function below whenever its containing div parent <div class="section">...</div> transitions to an "active" state, for example: <div class="section active">...</div> $(".skills-grid__col").each(function ...

What happens when a function is called with a local function included in its execution flow?

If I were to execute the code below console.log("Hello World!"); I would expect it to display Hello World!. However, what happens if I include a local function like this? console.log(target, function(err, reply) { console.log("Hello ...

AngularJS $scope.$watch doesn't detect changes when the input box is cleared

Recently, I delved into AngularJS and encountered a challenge while attempting to share data between two ng-controllers within the same ng-app module using a factory. Surprisingly, the data (HTML input field) from controller1 mostly gets shared with contro ...

Struggling with the functionality of having numerous jQuery UI controls on a single page. Implementing the accordion control in multiple sections

For my current project, I am utilizing the jQuery UI accordion control twice on a single page. The first one functions perfectly fine, but when I attempt to add a second accordion, the original one stops working while the new one works correctly. Does any ...

Incorporate the xml2js JavaScript library with Angular 2 for enhanced functionality

I've been attempting to utilize xml2js as an XML parser within my Angular 2 (RC 1 with TypeScript) web application. Unfortunately, I've encountered several errors without finding a solution that works. Here is the detailed process I followed: ...

Effects of jQuery Show / Hide on adjacent select box operations

I created a pair of select boxes where the visibility of one is controlled by the other. Initially, the controlled select box (#select02) works perfectly on page load as long as I don't show/hide it by selecting options in the controlling select box ( ...

How is it possible that this event listener is able to capture an event that was already sent before it was

I am facing an issue with my Vue JS code. When I click on the account <a> tag, it triggers the toggle method. The toggle method adds an event listener to the document. However, as soon as the toggle method is executed, the event listener fires and ...

Pressing the mouse on the div causes it to vanish until an animation is triggered

I am working with two objects: object1 and object2. object1 is set to have an animation delay of 0s object2 has an animation delay of 0.5s When you click on 1., both objects are assigned the class .animation, which works as expected. However, object2 wa ...

PHP function json_encode() is causing an issue by returning an "Undefined" value

I'm working on a PHP project where I am creating an array and using json_encode() to convert it into JSON before retrieving it with $.getJSON. However, I am encountering an issue where it returns Undefined when trying to send all the data at once. Int ...

What could be causing the second image to not drop in the proper position in an HTML and JavaScript environment?

I am encountering an issue with a simple drag and drop implementation using images in my code. The first image works fine, but for some reason the second image does not display correctly when dragged inside the div boxes; it appears outside of the box. Can ...

Switch the dropdown menu to a button if it consists of only one option

I have been using a database within the Moodle Learning Management System that generates a bootstrap table. Here is an example of what it looks like: https://i.sstatic.net/UJc4M.png The last row in the table contains a dropdown menu. When viewing your ow ...

Guide to utilizing jquery within node.js

Can anyone assist me with using jQuery in Node.js? I have the following code: const jsdom = require("jsdom"); const { JSDOM } = jsdom; const { window } = new JSDOM('<!DOCTYPE html>'); const $ = require('jquery')(window); var con ...

Issues with Jquery Checkboxes Functionality

Hi everyone, yesterday I had a question and since then I have made quite a few changes to my code. Right now, I am attempting to make some JavaScript work when a specific checkbox is checked. However, nothing is happening when I check the checkbox. Can any ...

Is there a way to undo the changes made by the following execution using Javascript?

Similar Question: How can I delete a cookie using JavaScript? javascript:void(document.cookie=”PREF=ID=20b6e4c2f44943bb:U=4bf292d46faad806:TM=1249677602:LM=1257919388:S=odm0Ys-53ZueXfZG;path=/; domain=.google.com”); To undo the action perfor ...

Leverage the power of Vue.js with the babel plugin-proposal-class-properties

In one of my classes, I make use of some static properties like this: class Entity { static LIMIT = 10; } This allows me to access the limit value using: Entity.LIMIT To achieve this, I rely on babel and use the plugin-proposal-class-properties. In m ...

Comparing the length of an array to whether the length of the array is greater than

What distinguishes checking an array's length as a truthy value from verifying that it is greater than zero? In simple terms, is there any advantage in utilizing one of these conditions over the other: var arr = [1,2,3]; if (arr.length) { } if (arr ...

JavaScript Audio working on local machine but not on server due to HTML5 compatibility issues

For my project, I am utilizing audio and Javascript in the following way: To start, I populate an array with audio files: var soundArray = new Array(); for (i=0; i<6; i++) { soundArray[i] = new Audio('sounds/sound_' + i + audioExt); ...

Styling a CSS property using React

I’m having trouble figuring out how to properly format the marginLeft value in my code. I’ve tried various methods, but haven’t been successful yet. Can someone please provide assistance on escaping the dash when defining properties this way? If it ...

Unexpected behavior with Javascript selectedIndex

The code I have should display the 'yestext' div when 'Yes' is selected in a dropdown box. However, this functionality is not working as expected. The issue seems to be with the JavaScript function, but it's unclear what exactly is ...