What exactly does the Javascript object syntax signify? (specifically in a Vue script)

Can anyone explain the purpose of this statement and the difference between using const and var?

const { SearchIcon } = myApp.icons;

I am currently exploring Vue and still relatively new to Javascript. This code snippet appeared in a tutorial example. The SearchIcon represents an icon imported from heroicons, while MyApp.icons is defined in another script file as shown below:

window.MyApp = {
    app: null,
    icons: {},
...

Answer №1

Seems like the issue lies in storing MyApp under the window object, but attempting to access it directly without following the correct syntax. The definition of MyApp has a capital M, whereas when accessing it, there is a lowercase m.

Here's an example that works:

window.MyApp = {
  app: null,
  icons: {
    SearchIcon : 'Hello!'
  },
};

const { SearchIcon } = window.MyApp.icons;

console.log(SearchIcon);

To learn more, refer to the object destructuring documentation.

Hope this explanation helps :)

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

Is there a way to retrieve the sub-child menu data from a JSON file?

I am currently working on creating a horizontal menu from a json file. However, I am facing issues in retrieving the subchild elements properly. Below is an example of my json file: var data = [{ "menu":[ { "MenuId":1, ...

Discover the secret to loading multiple Google charts simultaneously, despite the limitation that Google charts typically only allow one package to load at a time

I currently have a pie chart displaying smoothly on my webpage, but now I am looking to add a treemap as well. The code snippet for the treemap includes the package {'packages':['treemap']}. It has been stated that only one call should ...

Is there a way to store a SAFEARRAY (an array of bytes) into an HTML hidden field?

Is there a way to extract an array of bytes from an active-x component, save it in an html-form input hidden field, and then send it to the server using form-submit? I'm not sure how to accomplish this. MIDL: HRESULT Data([out, retval] SAFEARRAY(VAR ...

Does the downloading of images get affected when the CSS file has the disabled attribute?

Is it possible to delay the download of images on a website by setting the stylesheet to 'disabled'? For example: <link id="imagesCSS" rel="stylesheet" type="text/css" href="images.css" disabled> My idea is to enable the link later to tri ...

Issue with Webpack in vue.js project when incorporating sasssass causing errors

I am new to Vue.js and webpack, and I'm not sure if the issue lies with the packages or my own mistake. Steps to replicate the problem: Create a new Vue project using the webpack template ~ vue init webpack sass-test ? Project name sass-test ? Proj ...

Implement a function that attaches an event listener to generate a new table row dynamically

I am currently facing an issue with my table that has ajax call functionality to add rows within the tbody element. The table is already set up on the html page. <table id='mytable'> <thead> <tr> <th>First Col</th> & ...

Prevent Print Screen Functionality in Web Pages using jQuery or JavaScript

Is there a way to insert an image into my webpage while preventing users from saving it on their computers? I want to stop them from using the Print Screen button on their keyboards to capture images of my flash application. Can jQuery or JavaScript help ...

Examining the variances in reactivity between Vue.js 3 and Vue.js 2 using a basic demonstration

Currently, I am in the process of transitioning a project from Vue2 to Vue3. One issue that has arisen involves dynamic changes to objects not being reflected in the template. For instance, there is a class called TestClass with a property named duration. ...

What is the best way to save Vue state in a cookie while transitioning between form steps in a Laravel application

Imagine a scenario where a user is filling out a multi-step form, and we want to ensure that their progress is saved in case they lose connection. This way, the user's data will not be lost between different form steps. In addition to saving each ste ...

Implementing styles from a constant file in React Native: A simple guide

In my file register.js, I have a UI component. import CustomHeader from '../components/Header'; ... static navigationOptions = ({navigation, navigation: { state } }) => { return { title: '', headerSty ...

Is there a way to tally up the overall count of digits in a number using TypeScript?

Creating a number variable named temp in TypeScript: temp: number = 0.123; Is there a way to determine the total count of digits in a number (in this case, it's 3)? ...

Importing a file using its absolute path in JavaScript

Within the dependencies directory, there exists a module named foo: import foo from '../dependencies/foo'; // This import statement works as intended The challenge arises when attempting to import from a different path due to deployment in an AW ...

How can you selectively export a single function from a JavaScript file?

Within my project, I have two separate modules - one written in ts and the other in js. There is a utility within the js module that needs to be accessed by the ts module. The utility service.js looks like this: module.exports = { helloFriends: functi ...

Discover the versions of key libraries/modules within the webpack bundle

Is it possible to identify all the libraries, scripts, or modules included in a webpack bundle through the developer's console of a website that is already running, without access to its codebase? Additionally, is there a way to determine the version ...

The PHP code encountered a syntax error due to an unexpected $EOF on the final empty line

I've been tasked with maintaining an old website that went offline due to script errors. I managed to resolve most of the issues in the script, but there's one error that's giving me trouble. The site is showing a syntax error that says "une ...

Using async/await in an Express route handler

Currently, I am facing an issue with my node/express route. The route collects information through url parameters and then uses these parameters to trigger a separate function that takes some time to execute. Despite using async/await to pause the executio ...

Steps for transforming a JSON into a Class to generate objects

My JSON data is displayed below: var nodeclienthash={ socket:null, init : function() { // Initializing socket.io this.socket = new io.Socket(this.config.host, {port: this.config.port, rememberTransport: false}); } }; I am currently looking t ...

What is the method for selectively applying a "fade to black" mask to an input field?

For my current project, I need to incorporate a design feature where a "fade to black" mask gradually appears on the left side of an input field once the text content reaches the maximum visible width of the input box. The image below provides a visual re ...

Achieving SPA navigation compatibility with an external framework that employs innerHTML for content rendering

Within my Vue.js application, I am utilizing a bootstrap-based framework to automatically generate the HTML code for my header and navigation menu with links. This generated content is then inserted into the page by setting the innerHTML of a designated mo ...

What is the best way to replicate touch functionality on mobile browsers for both Android and iPhone devices?

Recently, while developing a web application, I ran into an issue on mobile browsers where the :active pseudo class wasn't functioning properly. I am currently utilizing CSS sprites and looking for guidance on how to simulate clicks for mobile browser ...