The error message "Vue is not defined in .vue file" indicates that there is a problem with

Hey there, I'm just starting out with Vue and have globally installed vue-cli. However, I encountered an error that says:

Uncaught ReferenceError: Vue is not defined
at eval (Hello.vue?13ca:73)
at Object.<anonymous> (main.js:1061)
at __webpack_require__ (main.js:679)
at fn (main.js:89)
at eval (Hello.vue?549c:1)
at Object.<anonymous> (main.js:1049)
at __webpack_require__ (main.js:679)
at fn (main.js:89)
at eval (index.js?fc04:1)
at Object.<anonymous> (main.js:1035)

This is how my main.js file looks like:

import 'bootstrap';
import Vue from 'vue';
import App from './App';
import router from './router';


Vue.config.productionTip = false;

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: {
    App,
  },
});

Since index.js is also referenced, here's the code for it:

import Vue from 'vue';
import Router from 'vue-router';
import Hello from '../components/Hello';


Vue.use(Router);

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Hello',
      component: Hello,
    },
  ],
});

The root of the error seems to be this part in the Hello.vue file. When removed, everything works fine:

<script>
var nav = new Vue({  
  el: '#loginButtons',
  methods: {
    open: function(which, e) {
      // Prevents clicking the link from doing anything
      e.preventDefault();
    }
  }
});
</script>

Answer №1

In order for single file components to work properly, the <script> tags must contain an export statement with the object that would typically be passed to the new Vue() constructor. Additionally, the el property is not necessary as Vue will automatically use the <template> as the root element.

<script>
export {
  methods: {
    open: function(which, e) {
      // Prevents clicking the link from doing anything
      e.preventDefault();
    }
  }
};
</script>

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 best way to adjust the size of a button using CSS within a ReactJS

I am facing an issue where I need to create a button with a specific width, but the template I'm using already has predefined styles for buttons. When I try to customize the button's style, nothing seems to change. Below is the code snippet: Her ...

Tips on setting up the table with php and javascript

My PHP and JavaScript code displays data in the wrong format. The row consists of classcode, courseNumber, courseDescription, units, time, days, room, but it's not arranged correctly. I want it to display each piece of data under its respective column ...

What is causing the error in this particular stream function?

I created a function that logs the provided arguments to the console when piped into it. function logToConsole() { var stream = new Stream.Transform({objectMode: true}), args = [].slice.call(arguments); stream._transform = function (data, ...

Using Vue.js to make AJAX requests

I am facing an issue while trying to fetch data from an API endpoint api/data which returns an object. However, when I run my application, nothing shows up in the console and there are no XHR requests visible in the network tab. There are no warnings or er ...

Utilizing axios and Vue to access the Twitch API

Currently, my goal is to integrate the Twitch API for user sign-ins, but I've encountered some challenges along the way. Below is the initial code snippet that I have developed: <template> <section> <form class="pt-6 pb-8 animat ...

JavaScript - Global Variable

Is it possible to declare and assign a value to a global variable in one JavaScript file and then reference it in another JavaScript file multiple times? Can Angular.js be utilized in a Velocity macro file, aside from HTML files? ...

SignalR blocking axios requests (In a Waiting State)

I am currently developing a project that involves bidding on products in Auctions with real-time updates of the bid price. With potentially thousands or even millions of users worldwide participating in the bidding process. We have implemented SignalR for ...

Identifying the moment a member receives a role using my Discord bot built with discord.js

I am currently working on detecting when a user is assigned a specific role on a server. Here is the code I have been using: // Require the required discord.js classes const { token } = require('./config.json'); // Create a new client instance ...

Managing Redirects Following AJAX Requests in JavaScript / jQuery

I have a situation where I'm using an ajax call and attempting to redirect my page to a different URL after the call is made. However, instead of redirecting, the page just refreshes. How can I successfully redirect my page? <button onclick="Sign ...

Is it possible to integrate external search functionality with Vuetify's data table component

I am currently working with the v-data-table component from Vuetify, which comes with a default filter bar in its properties. This table retrieves data from a local JSON file. The issue arises when I have another external component, a search bar created u ...

Encountering complications in compiling Vue components

As I'm fairly new to Vue.js, please bear with me. I've been working on a project where I created two new Vue components – one being a tab/toggle element and the other a cookie banner. However, when both are added to the page, the cookie banner ...

What prevents me from extending an Express Request Type?

My current code looks like this: import { Request, Response, NextFunction } from 'express'; interface IUserRequest extends Request { user: User; } async use(req: IUserRequest, res: Response, next: NextFunction) { const apiKey: string = ...

Using $.ajax() to store data in the database

Is there a way to save dynamically generated elements from my application.js file into the database? Would the code be similar to this example?: $.ajax({ type: "POST", data: { title: 'oembed.title', thumbnail_url: 'oembed.thumbnail_ur ...

ways to display nested arrays in angularjs

I'm having an issue with binding and displaying the value of an array. When I assign the value using the scope variable like this: $scope.StockList = obj.data Everything works fine. However, when I try to push the value into the array like this $ ...

ScriptManager and UpdatePanel don't recognize the definition of Sys

After utilizing the ScriptManager and UpdatePanel in asp.net 4.0, I encountered an error upon deploying the code to the server. Upon inspecting the browser console (F12), I found the message "Sys is not defined" in the generated js code by ScriptManager. & ...

The v-for directive on a reactive Vuejs array is failing to render its elements

After much searching, I have identified the error and provided a brief explanation in the following paragraph. The code below resolves the error by changing the approach of the code rather than fixing the error itself. By defining the indexes of the array ...

What is the correct way to properly insert a display none attribute

I'm experiencing some alignment issues with the images in my slideshow. I used this example as a reference to create my slide: https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_slideshow_dots When clicking on the next image, it seems to mo ...

Active positioning within a parent div

I'm having difficulty getting a color picker JavaScript widget to function properly within a webpage that contains unchangeable elements. Some of these elements are causing the color picker to be displayed far below the link once clicked. Here is a si ...

Updating HTML content based on changes in JSON data using Javascript/Python/d3JS

In my current project, I am able to manipulate a d3JS interface using another platform. The process involves generating data in Python to create JSON, which is then used by d3JS to produce graphics. Finally, the HTML page containing the graphic is loaded l ...

Having difficulty deleting an entry from a flatList in a React Native component when using the filter method

I'm currently facing an issue with deleting an item from my flatlist in React Native. I've been attempting to use the filter method to exclude the list item with the ID entered by the user for deletion, but it's not working as expected. I&ap ...