The local server is having trouble loading JavaScript

I've been troubleshooting a sleek menu design, and I'm puzzled by why it's not working on my localhost. It functioned perfectly when tested on this Codepen. However, after transferring the code to my localhost, it stopped functioning. I'm seeking assistance in identifying the reason for this issue. Please refer to the images below to view the current output. (UPDATED---from this image output: https://i.sstatic.net/n6RXd.jpg

Here's what I'm currently observing. Since it was working fine on your end, I suspect it might be related to the placement of my external codes. Although the animation functions to some extent (when hovered), it appears that the project category content is not being fetched correctly. Could this be due to how I've positioned my declarations or could it be something else? https://i.sstatic.net/1tzMD.jpg

Below is the code I'm using

index.html

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Responsive Stylish Menu</title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js"></script>
        <script type="text/javascript" src="js/main.js"></script>
    <link href="css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>

<body>
<h2>Our Brands</h2>

<div id="projectsApp">

  <div class="projects" :id="project.ID" v-for="project in projects" :style="{ backgroundImage: 'url(' + project.bImage + ')' }" v-on:click="selectProjects(project.ID)">
    <h3 class="beforeTitle"> {{ project.category }}</h3>
    <div class="info">
      <h1 class="fadeTitle"> {{ project.category }}</h1>
      <hr>
    </div>
    <p class="backArrow"><i class="fa fa-angle-double-left" aria-hidden="true"></i></p>
  </div>

  <div class="selectedArea">
    <h1 :style="{ backgroundImage: 'url(' + highlightedContent.bImage + ')' }"><span>{{ highlightedContent.category }}</span></h1>
    <div v-html="highlightedContent.copy" class="copyArea fadeIn"></div>
  </div>

</div>

</body>

</html>

style.css

@import url("https://fonts.googleapis.com/css?family=Open+Sans");
* {
  box-sizing: border-box !important;
  font-family: 'Open Sans', sans-serif; }

::-webkit-scrollbar {
  width: 12px !important;
  height: 10px;
  background-color: #ffffff;
  border-top: 1px solid #090909; }

::-webkit-scrollbar-thumb {
  background-color: #976734;
  height: 5px; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0; }

h2 {
  text-transform: uppercase;
  font-weight: 100;
  letter-spacing: 50px;
  float: left;
  text-align: center;
  width: 100%; }
  
  ...

main.js

...

Answer №1

The code was tested and is functioning flawlessly. Try the following code snippet and ensure that CSS and JS files are properly imported to your HTML file.

Make sure to import the below Vue JS file into your local HTML file.

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js"></script>

<html>
   <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js"></script>
      <style>
         @import url("https://fonts.googleapis.com/css?family=Open+Sans");
            /* CSS styles */
      </style>
   </head>
   <body>
      <h2>Our Brands</h2>
      <div id="projectsApp">
         <div class="projects" :id="project.ID" v-for="project in projects" :style="{ backgroundImage: 'url(' + project.bImage + ')' }" v-on:click="selectProjects(project.ID)">
            <h3 class="beforeTitle"> {{ project.category }}</h3>
            <div class="info">
               <h1 class="fadeTitle"> {{ project.category }}</h1>
               <hr>
            </div>
            <p class="backArrow"><i class="fa fa-angle-double-left" aria-hidden="true"></i></p>
         </div>
         <div class="selectedArea">
            <h1 :style="{ backgroundImage: 'url(' + highlightedContent.bImage + ')' }"><span>{{ highlightedContent.category }}</span></h1>
            <div v-html="highlightedContent.copy" class="copyArea fadeIn"></div>
         </div>
      </div>
      <script>
         /* Vue JS scripts */
      </script>
   </body>
</html>

Answer №2

Revamp your code:

data() {
    return {
       projects: myProjects,
       highlightedContent: theHighlightedContent
    };
},

Convert from a function to JSON format:

data: {
        projects: myProjects,
        highlightedContent: theHighlightedContent
      },

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

How to Add a Dynamic Underglow Effect to Your Bootstrap Navbar?

This is my first question on this platform, but I have been using it extensively while learning web development and various other skills. A friend and I have been using Bootstrap to create a website, and we have come across some incredibly stunning navbars ...

Unlock the power of jQuery chaining with the val() method

My selected background color is set to: var _back = "#FF0000"; Why doesn't this code change the input field's background color: $("#input").val( _back ).css("background-color",$(this).val()); But this one does? $("#input").val( _back ) ...

JavaScript function not executing

Within a panel in an UpdatePanel, there is both a dropdown list and a file upload control. The goal is to enable the Upload button when a value is selected from the dropdown and a file is uploaded. This functionality is achieved through a JavaScript functi ...

Instructions for altering the hue of a canvas square when the cursor hovers over it

I want to implement a feature where the color of a tile changes when the user hovers their mouse over it, giving it a whitened effect. The tileset I am using consists of 32x32 tiles. Below are the scripts for reference. MAP.JS function Map(name) { ...

Showcasing an item hidden behind text and a dropdown menu

I have made changes to the background image in my Wordpress theme and now I want to display another image on top of the white content area. To achieve this, I used the following code: img style="position: absolute; top:244px; left: 220px;" src="http://ww ...

Having issues when dynamically adding options to a multiselect dropdown

I'm working on dynamically adding options to a multiselect using AJAX: <select size='2' name="CraftCode" id=@ccrf class="form-control js-select manualentrydd" ></select> $.ajax({ type: "GET", url: "GetCraftCodes", data: ...

Inserting a Specific Iframe into a Designated Location in HTML with the Help of Jquery

Currently, I am encountering an issue with placing a dynamically created iframe inside a specific section of my webpage. The iframe is supposed to be contained within a div element named "maps", but instead it is appearing at the bottom of the page.This ma ...

Is it permissible to enclose useEffect hooks within an IIFE?

Currently, I am dealing with a project that is rife with anti-patterns. One issue that has caught my attention is the use of Immediately Invoked Function Expressions (IIFE) around multiple useEffect hooks. Here is a snippet of the code in question: conditi ...

Creating Sleek Rounded Corners with Pure CSS in Older Versions of Internet Explorer (Compatible with jQuery)

Looking for a seamless solution to render rounded corners on browsers that do not support CSS3 without the delay typically seen with JQuery plugins. The use of .htc files with www.css3pie.com seems like the best option so far, but there is still a delay c ...

Guide to positioning a card in the middle of a container using Bootstrap

I am struggling to center a card inside a container using CSS properties like justify-content-center, mx-auto, and hardcoding. However, I have not been able to achieve the desired result. Here is the code snippet from my HTML file: <div class="cont ...

What is the significance of incorporating vinyl-source-stream into gulp in my workflow?

Recently, I've been experimenting with gulp and browserify to convert my .jsx files into .js files. var gulp = require('gulp'); var browserify = require('browserify'); var reactify = require('reactify'); gulp.task(&apos ...

ReactJS: Error in syntax detected in src/App.js at line 16, column 6. This token is unexpected

Just starting out with reactjs and encountered a simple example in a tutorial. Ran into a syntax error when trying to return html tags. Below is the error that popped up: ./src/App.js Syntax error: C:/Users/react-tutotial/src/App.js: Unexpected token ...

Tips for concealing divs when hovering over them

I have designed a header for my website with the following styles: .header-cont { width:100%; position:fixed; top:0px; } .header { height:50px; background:#F0F0F0; border:1px solid #CCC; width:950px; margin:0px auto; } .hea ...

Nested arrays in the JavaScript programming language

Is this JavaScript code accurate: var options = []; options.push(["Tom","Smith"]); options.push(["Mary","Jones"]); where each item in options is a two-element array of strings. I plan to add items to options using a for loop. Furthermore, can I i ...

Troubleshooting connection timeouts between node.js and amqp

In my project, I am utilizing RabbitMQ through the AMQP module in Node.js with 2 producers and 2 consumers. Here is the code snippet for establishing connections for the consumers: function init_consumers( ) { console.log( 'mq: consumers connect ...

Discover the process of computing an array of numbers using Vue.js

I need help with a code snippet that involves adding up the "debit" field values in an array to find the total. I've attempted to use the reduce function for this purpose, but it seems to be treating the numbers as characters instead of computing thei ...

Establish the geolocation within the data object once Vue.js has been mounted

Just dipping my toes into the world of VueJS. I've got a side project in the works that hinges on fetching User's Geolocation Data right after the main component has mounted. My code snippet is as follows: var app = new Vue({ el: '#app&a ...

PHP code cannot be outputted to JavaScript due to a syntax error

Although there is a syntax error, the code seems to be working. I am curious about how to make it syntactically correct. The provided code snippet is part of a script that sets up variables for an Ajax call. Depending on the scope, the corresponding varia ...

The Gulp task abruptly terminates before the Stream has a chance to trigger the "end" event

const gulpJasmine = require('gulp-jasmine'); const gulpDebug = require('gulp-debug'); function runTest(platform, testType) { const timer = startTimer(); console.log('started!'); return gulp.src('./src/**/_test/**/ ...

Utilizing getUserMedia to capture portrait shots with the back camera

I am encountering an issue with starting the back camera in portrait mode using navigator.mediaDevices.getUserMedia in React. The camera does not appear to be taking into account the constraints I have set. Below is how the code looks for initialization: ...