The error message "Seed is not defined" is raised when the program attempts to

I'm currently diving into fullstack vue and I'm perplexed by the error occurring in this particular scenario.

window.Seed = (function () {
    const submissions = [ 
        { 
            id: 1, 
            title: 'Yellow Pail', 
            description: 'On-demand sand castle construction expertise.', 
            url: '#', 
            votes: 16, 
            avatar: '../public/images/avatars/daniel.jpg', 
            submissionImage: '../public/images/submissions/image-yellow.png', 
        } 

    ];
    }());

This snippet showcases the seed function, essentially our example's database.

<!DOCTYPE html> 
<html>
    <head>
         <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.5.3/css/bulma.css">
          <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.6/css/all.css"> 
         <link rel="stylesheet" href="../public/styles.css" /> 
    </head>
    <body>
        <div id="app"> 
            <h2 class="title has-text-centered dividing-header">UpVote!</h2>
            <div class="section"> 
                <article class="media"> 
                    <figure class="media-left"> 
                        <img class="image is-64x64" v-bind:src="submissions[0].submissionImage"> 
                    </figure> 
                    <div class="media-content"> 
                        <div class="content"> 
                            <p> 
                                <strong> 
                                    <a v-bind:href="submissions[0].url" class="has-text-info">
                                     {{ submissions[0].title }} 
                                    </a> 
                                    <span class="tag is-small">
                                        #{{ submissions[0].id }}
                                    </span> 
                                </strong> 
                                <br> 
                                {{ submissions[0].description }} 
                                <br> 
                                <small class="is-size-7"> Submitted by: 
                                    <img class="image is-24x24" v-bind:src="submissions[0].avatar"> 
                                </small> 
                            </p> 
                        </div> 
                    </div> 
                    <div class="media-right"> 
                        <span class="icon is-small"> 
                            <i class="fa fa-chevron-up"></i> 
                            <strong class="has-text-info">{{ submissions[0].votes }}
                            </strong> 
                        </span> 
                    </div> 
                </article> 
            </div>    
        </div>
        <script src="https://unpkg.com/vue"></script>
        <script src="./main.js"></script> 
         <script src="./seed.js"></script> 

    </body>
</html>

This represents my index.html file.

new Vue({
         el: '#app',
         data: { 
            submissions: Seed.submissions 
         }
         });

Lastly, here is my main.js responsible for connecting index.html with seed.js. Unfortunately, it seems to be malfunctioning.

Answer №1

Check out the following code snippet:

document.addEventListener('DOMContentLoaded', (event) => {
    window.Seed = (function () {
        const submissions = [ 
            { 
                id: 1, 
                title: 'Yellow Pail', 
                description: 'On-demand sand castle construction expertise.', 
                url: '#', 
                votes: 16, 
                avatar: '../public/images/avatars/daniel.jpg', 
                submissionImage: '../public/images/submissions/image-yellow.png', 
            } 

        ];
       window.Seed.submissions = submissions;
    }());
})

Add this code to your index.html file:

new Vue({
    el: '#app',
    data: { 
        submissions: window.Seed.submissions 
    }
});

By implementing this solution, you should resolve the issue. The problem with your initial code was caused by

window.Seed having the self-invoking function
which didn't return anything, preventing you from setting the submissions property in the window.Seed object. Hopefully, this explanation clarifies things for you.

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

What is the significance of -= and += operators in JavaScript programming language?

I'm puzzled by the mathematical process behind this JavaScript code, which results in -11. let x = 2; let y = 4; console.log(x -= y += 9) ...

Discovering a specific URL link element within the DOM using webdriver.io

I am currently utilizing webdriver io for conducting tests on a webpage. I am in need of verifying the existence of an element with a specific href on the page. I have attempted to achieve this using the following snippet var client = webdriverio.remote ...

I am facing an issue where my Javascript hide and show function is not working properly when clicked. Despite not giving

I am currently working on a Javascript onClick function to toggle the visibility of content in a lengthy table. I initially set part of the table's class to display: "none" and added a button to show the hidden content when clicked. However, nothing i ...

What is the appropriate command for "building" a fresh NPM project?

I'm currently working on a JS website with Three.js. I kicked off my project like this: $ npm init $ npm install three Can anyone guide me on where to place my code utilizing Three.js, and which npm command should I use to "compile" my script for dep ...

What is the procedure for configuring a proxy in Nuxt3?

Attempting to launch a Nuxt3 program, I am encountering issues with setting up a server proxy. When making a request to http://localhost:3000/api/v1, it is expected to return a response from our backend server located at . However, all I receive now is a 4 ...

The file 'index.js' does not have a default export

Stepping into the world of MERN development, I embarked on a journey to construct a learning management system based on an outdated tutorial. To my dismay, I encountered the following error: > ..\server\middlewares\index.js:1 > import ...

What are the best ways to keep a django page up to date without the need for manual

Currently, I am in the process of developing a Django website focused on the stock market. Utilizing an API, I am pulling real-time data from the stock market and aiming to update the live price of a stock every 5 seconds according to the information pro ...

Explore all potentialities within an array of objects by examining and contrasting their key values

Looking to run a specific math formula with three parameters using an array of objects in JavaScript. The scenario involves sports, where there are three possibilities: Team A (win), Team B (win), or Draw. There are three different bet websites offering o ...

The replace() function is failing to replace the provided inputs

Supposedly, when a user types in certain profanity and submits it, the word is supposed to be replaced with a censored version. Unfortunately, this feature is not working as expected. The word appears uncensored. Do you think implementing if/else stateme ...

Compose an email in Vue.js without relying on any third-party API integration

Looking to send emails via SMTP Protocol without relying on any third-party integrations or APIs. Please provide a detailed, step-by-step solution. No need for existing code reflection, just ensuring error-free execution. ...

The JSON object is coming back as null

I need some clarification on why I am getting an "undefined" alert. Any assistance you can offer would be greatly appreciated as this problem is holding up progress on a crucial project. JavaScript $.getJSON("item-data.json", function(results) { ...

The styled-components seem to be having trouble injecting the necessary CSS to handle all the various props

I am curious to understand the potential reasons for styled-components not injecting all the necessary CSS into a page's header. In an existing project, I have defined a simple button like this: const Button = styled.button` background-color: ...

How to Call a Method from a Different Component in Vue 3

Just a quick question, as I am still getting the hang of Vue.js... Greetings! Is it possible to call a method from one component in another? Let's say I have two components: componentOne.vue <template> <section> <div> ...

Dividing a JSON string and incorporating them into individual tds using AngularJS

Currently, I am working on extracting values from a JSON string by splitting it at the ":" and displaying the two values in separate td tags. function testCtrl($scope) { $scope.response = {"name":["The name field is required."],"param":["Hobby: Coding", " ...

The functionality of saving a file using the jsPDF method is not functioning properly

After dedicating four days to resolving a seemingly straightforward task that involved the jsPDF library, I found myself faced with a challenge. My goal was to save a file using this library, not just print it like I had successfully done before. This is ...

Utilize promise-style for Sequelize associations instead, please

I am in the process of merging information from 3 tables - Products, Suppliers, and Categories. My goal is to retrieve the row with SupplierID = 13. I recently came across a helpful explanation on How to implement many to many association in sequelize, whi ...

Applying an active class in VueJs to a specific li element within a v-for loop when clicked

Struggling to select (set active class) in a v-for loop when one class is already selected. Here's the code and an explanation: These are my available subscriptions, with one already selected based on user data <ul> <li v-for="(s, key, ...

Upon loading the page, I encountered an issue with the 'errors' variable in my ejs template, resulting in an 'undefined' error

When I load my page, I encounter an 'undefined' error with my 'errors' variable in the ejs template. The ejs template I have is for a contact form and it includes code to display errors as flash messages on the page if the form is inco ...

jQuery allows us to set two separate conditions for two distinct variables

I've written this function: settings_rc_left.on('click', function(){ var settings_list_last_element_id_one = settings_menu_element.attr('id') == 'r_02', settings_list_last_element_id_two = settings_menu_eleme ...

Discovering the smallest, largest, and average values across all properties in an array of objects

Given an array of objects with varying values, the task is to determine the minimum, maximum, and average of the properties in that array. For example, consider the following array: const array = [{ "a": "-0.06", "b": "0.25", "c": "-0.96", ...