Having trouble with VSCode correctly importing my main.js file

My main.js file isn't being imported in VScode and I'm at a loss for what the issue could be. Even though the index.html is adjacent to main.js, it's unable to locate it. I've successfully imported multiple js files into html in the past, so why is it failing now? Does anyone have any insights?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Vue Mastery</title>
    <!-- Import Styles -->
    <link rel="stylesheet" href="./assets/styles.css" />
    <!-- Import Vue.js -->
  </head>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e1979484a1d3cfd7cfd0d5">[email protected]</a>/dist/vue.js"></script>
    <div id="app">
      <h1>{{ product }}</h1>
    </div>

    <!-- Import Js -->
    <script src="./main.js"></script>
    <!--Mount App-->
    <script>
      const mountedApp = app.mount;
    </script>
  </body>
</html>

I'm encountering issues with using the js file here because it's not linking properly to the html, causing "Vue is not defined" errors.

const app = Vue.createApp({
    data() {
        return{
            product: 'Socks'
        }
    }
})

The directory structure appears as follows:

Intro-to-Vue
-Assest
 -Images
  Socks.png
Index.html
main.js

Your assistance would be greatly appreciated. Thank you!

Answer №1

It seems that you are mixing Vue 3 syntax with a Vue 2 CDN script :

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Vue Mastery</title>
    <!-- Import Styles -->
    <link rel="stylesheet" href="./assets/styles.css" />
    <!-- Import Vue.js -->
  </head>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3046455570021e061e0104">[email protected]</a>/dist/vue.js"></script>
    <div id="app">
      <h1>{{ product }}</h1>
    </div>

    <!-- Import Js -->
    <script src="./main.js"></script>
   
  </body>
</html>

and main.js should be structured like this:

   new Vue({
      el: '#app',
      data() {
        return {
          product: 'Socks'
        }
      }
    })

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

Searching and filtering through the Quasar Intersections

I want to implement a filter and search feature for a QIntersection in Quasar, similar to the functionality of a QTable. The goal is to be able to search through an entire JSON dataset. My plan is to use a v-for loop to iterate over the JSON data and crea ...

Generate a new passport session for a user who is currently logged in

I am currently utilizing passport js for handling the login registration process. After a new user logs in, a custom cookie is generated on the browser containing a unique key from the database. Here's how the program operates: When a new user logs ...

The vue-cli 3.0 command runs on multi (webpack)-dev-server/client at the URL http://10.0.68.112:8080/sockjs-node, using webpack hot dev-server from ./src/main.js

While working on the project, I encountered an error when running vue-cli-service serve because the main.js file is not located in the src root directory. The error message reads as follows: * ./src/main.js in multi (webpack)-dev-server/client?http://10 ...

The D3 force layout is currently displaying just a single connection

I've been experimenting with a graph that I found in this demo and now I want to modify it to display data from Spotify. I created a sample JSON file and adjusted the script accordingly for the new data format, everything seems to be working fine exc ...

How can I access the express variable from within AngularJS?

initial exports.render = function(req,res){ res.render('index', { title: 'welcome', username : req.user ? req.user :'' }); }; I am looking to transfer object req.user for utilization h2 Hello #{user ...

Tips for creating an option list on the fly

In need of help here! I have a dropdown list that needs to be dynamically populated using jQuery because the list contents are constantly changing. I initially got the code inspiration from a website, but it was built with a fixed number of items in mind. ...

Could anyone provide an explanation of the current situation in this section of the code?

I am currently working on a piece of code that looks like this: ruter.get('/', async function (_, res) { const [categories, items] = (await Promise.all([ db.query('SELECT * FROM categories'), db.query('SELECT * FROM invento ...

Tracking dependencies in Vue 3 after running asynchronous code using watchEffect

I am currently grappling with the concept outlined in this note from the watchEffect documentation TIP watchEffect only keeps track of dependencies during its synchronous execution. When employed with an asynchronous callback, only properties accessed be ...

Trouble arises with Pagination feature of Mui Data Table

Currently, I am working on a project that involves retrieving data from the CoinMarketCap API and presenting it in an MUI Data Table (specifically a StickyHeader Data Table). However, I have been encountering difficulties with changing the color of the tex ...

Data in JSON format is not sourced from a text file

My latest project involved creating two new files within a folder titled "hello". These files are named index.html and jsontext.txt. The contents of index.html look like this: <!DOCTYPE html> <html> <head> <title>Experiment< ...

What could be the reason behind the absence of this.props.onLayout in my React Native component?

In my React Native app, I have the below class implemented with Typescript: class Component1 extends React.Component<IntroProps, {}> { constructor(props){ super(props) console.log(props.onLayout) } ... } The documentation for the View ...

Is it possible to execute PHP without using Ajax when clicking on a Font Awesome icon?

So, besides using Ajax, is there another solution to achieve the same result? Can a font-awesome icon be turned into a button without Ajax? In case you're unfamiliar with what I mean by a font-awesome icon, here's an example: <i id="like1" on ...

A comprehensive guide on making an AJAX call to a self-hosted servlet

I created a servlet in Eclipse IDE for Java EE that posts data as an XML page and hosted it on a Tomcat server. The servlet can be accessed at http://localhost:8080/Checkers/CheckersServlet. When I open this URL in Firefox, the XML loads correctly. Now, I& ...

Prevent textArea from reducing empty spaces

I am facing an issue with my TextEdit application set to Plain Text mode. When I copy and paste text from TextEdit into a textarea within an HTML form, the multiple spaces get shrunk. How can I prevent the textarea from altering the spacing in the text? T ...

The Facebook app is designed to require users to grant permission for the application to access their personal data

I am developing an application that replicates Facebook's functionality. When a user purchases my application, they are granting permission for my application to access their data on Facebook. Is there a way to programmatically click on the "Allow App ...

Having trouble with ajax file upload using jQuery version 1.9.1 and higher?

I am experiencing an issue with my file upload form when using jQuery versions 1.9.1 and above. The form uploads files to Amazon S3 with a generated policy, and while it works perfectly fine with jQuery <=1.9.0, it seems to be broken in the newer versio ...

What is the best way to retrieve the dimensions of a custom pop-up window from the user?

Currently, I am in the process of developing a website that allows users to input width and height parameters within an HTML file. The idea is to use JavaScript to take these user inputs and generate a pop-up window of a custom size based on the values pro ...

Preload-webpack-plugin does not support pre-fetching files

I have a query about prefetching and preloading content. In my vue app, I noticed that after building, I have duplicate files loaded in my dist/index.html file. Here is an example: Additionally, the "scripts" are not being preloaded/prefetched as expec ...

Adding conditional href based on a specific criteria to an <a> tag in AngularJs

I have been working on a menu list where some menus contain URLs and others do not. When a menu item includes a URL, the href attribute is displayed, otherwise just the span tag is shown. I tried checking it like this but ended up with href="#" when the me ...

Is there a way to link the scrolling of two ag-grid data tables together for synchronized movement?

I have integrated ag-grid into my Angular project and I am looking to display two data tables (ag-grid) stacked on top of each other. Both data tables should scroll together, meaning when I scroll in table 1 or table 2, the content of both tables should m ...