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

Guide on how to reference the Html directory using the path module in Node Js

Desperately trying to send an html file as a response using express, but I'm having trouble locating the position or path of the index.html file. This is how my files are structured - MyWebsite Html index.html Css index.css ...

Use jQuery to switch back and forth between the login and registration forms on a single

I've set up two forms, one for login and one for registration, with the default view showing the login form. There's a link that says "Don't have an account?" and when it's clicked, the registration form will display while the login for ...

Having trouble with Javascript files failing to load while hosting a website on digital ocean?

Recently, I developed a web application using an express backend and the ejs view engine. Everything works perfectly fine when tested on my local machine. However, I encountered issues when trying to host it on a digitalocean droplet (Ubuntu 22.10 x64). Af ...

Disable the time selection feature in the text input field

Despite seeing the same question asked before for this issue, I am looking for a solution that does not involve replacing the textbox with the same ID. When Timepicker is selected in the dropdown menu timepicker, it should activate in the textbox (which i ...

The chat message section is failing to update due to AJAX not refreshing

I recently launched a new website and am facing challenges with the chat feature. Despite using ajax to update the chat messages without refreshing the page, the other user still needs to refresh in order to see the latest message. We are both in the sam ...

Inserting multiple rows of data into a MySQL database in a single page using only one query in PHP

This snippet shows a MySQL query being used to update and insert data into a database: if ($_POST["ok"] == "OK") { $updateSQL = sprintf("UPDATE attend SET at_status=%s, at_remarks=%s WHERE at_tt_idx=%s", GetSQLValueString ...

Function used to update database through AJAX technology

I have implemented a PHP script to update my database using AJAX, and it is working correctly after being tested. To pass the required two variables to the PHP script for updating the database, I created a JavaScript function that utilizes AJAX to call the ...

Discover how to generate nested dynamic routes in NextJS by linking to MongoDB data using the getStaticProps and getStaticPaths functions

Currently, I am facing a challenge with implementing dynamic paths in NextJS and I'm struggling to find a solution. Let me provide some context for better understanding. I am working on developing an ecommerce application using NextJS, and the folder ...

transmit information and documents to server using Axios

I am working on a project using ReactJs and I need to send data to a Laravel API using Axios. Here is the code snippet I have tried: export const send = (data, File) => { const formData = new FormData(); formData.append('media', File); ...

Is it possible to check dynamically if a string contains multiple substring matches?

Currently, I am in the process of developing a search suggest feature that will provide the best match based on certain criteria. Below is the code snippet along with my explanatory comments. /* string = {"Canna Terra PLUS 50 Litres", "Canna Vega ...

Is there a way to adjust the size of the canvas element in HTML without compromising quality or resorting to zooming?

I'm currently working on a basic modeling application for the web. The main component of my app is a canvas element that I'm trying to size correctly. However, when I set the height and width using CSS, it scales the entire canvas and compromises ...

An issue arises in vue.js where the v class binding takes precedence over other bindings and fails to properly remove

I have a game with a punching bag where I want to incorporate an animation class each time the bag is clicked. Once the health meter hits zero, I intend to replace the bag image with one depicting a burst bag. Things are running smoothly up until the poin ...

Ways to detect when the window printing process has been completed

Within my application, I attempted to generate a voucher page for the user using the following code: var htm ="<div>Voucher Details</div>"; $('#divprint').html(htm); window.setTimeout('window.print()',2000); The &apo ...

Manipulate a JSON object with JavaScript

Struggling to find a solution on my own. In my hidden field, I have some JSON data stored. To retrieve this data, I'm using the following syntax: $(document).ready(function() { var data = $("#result").text(); var j = JSON.parse(data); j.my_item.to ...

Changing the index of an item in an array in React based on order number

Hey there, I'm a new Reactjs developer with a question. It might be simple, but I'm looking to learn the best practice or optimal way to change the index of a selected item in an array based on user input. Essentially, the user will provide a num ...

Transferring information from parent page to child page using Angular version 8.2.4

As a newcomer to Angular, I am facing a challenge in sharing data between pages upon loading the main page. The structure involves using dynamic forms to generate dynamic pages within the main page. However, when trying to pass data from the main page to t ...

Error message: The method app.get() is invalid as it is not a

I'm having trouble using Express in a prototype function ioServer() { } module.exports = ioServer; ioServer.prototype.start = function() { var app = require('express') var http = require('http').Server(app) ...

Always ensure that only one div is visible at a time

I am currently working on a project where I cannot use ng-cloak due to the way the css files are loaded. I have been exploring alternative solutions and have tried a few different approaches. My main goal is to ensure that two icons are never shown at the ...

React: Implementing localStorage token addition in loginHandler function using State hook is not functioning as expected

I've implemented an AuthContextProvider in my React application to handle user authentication and logout functionality: import React, { useState } from "react"; import axios from "axios"; import { api } from "../api"; co ...

Issue with Nuxt.js generate freezing at 'generated' stage

Just delving into the world of Nuxt App development for the first time and I'm facing a challenge while trying to deploy it on netlify. Whenever I run the command yarn run generate No errors are thrown, but my progress halts at this point: Built at ...