2

Description: I am working on a leaderboard web application using Vue.js. After completing my code, I attempted to launch the server on localhost, but encountered an error. The error message I received is as follows:

Uncaught runtime errors:

ERROR
Cannot read properties of undefined (reading 'use')
TypeError: Cannot read properties of undefined (reading 'use')
    at eval (webpack-internal:///./src/router.js:10:45)
    at ./src/router.js (http://localhost:8080/js/app.js:79:1)
    at __webpack_require__ (http://localhost:8080/js/app.js:203:33)
    at fn (http://localhost:8080/js/app.js:436:21)
    at eval (webpack-internal:///./src/main.js:4:65)
    at ./src/main.js (http://localhost:8080/js/app.js:69:1)
    at __webpack_require__ (http://localhost:8080/js/app.js:203:33)
    at http://localhost:8080/js/app.js:1324:109
    at __webpack_require__.O (http://localhost:8080/js/app.js:249:23)
    at http://localhost:8080/js/app.js:1325:53

I tried creating a new project to fix the error, but the problem persists. I also made sure to repeatedly install both Vue and Vue Router, but that didn't resolve the issue. I am seeking assistance in identifying and resolving the problem.

import Vue from "vue";
import VueRouter from "vue-router";

import Scoreboard from "./components/ScoreboardTable.vue";
import Submissions from "./components/SubmissionDetails.vue";

Vue.use(VueRouter);

const routes = [
  { path: "/scoreboard", component: Scoreboard },
  { path: "/submissions/:problemId", component: Submissions },
];

const router = new VueRouter({
  routes,
});

export default router;

The objective of this project is to develop a single-page app for viewing a competition's scoreboard. The app should have two pages: the Scoreboard page and the Submissions page, each serving a specific purpose.

I appreciate any assistance in locating and fixing the issue. Thank you in advance!

2

1 Answer 1

3

You are using Vue 3, but instantiate vue-router as you would have in Vue 2 (Vue.use(...))

With Vue 3, you create the router with createRouter() and add it to the app instance (instead of a global Vue object):

import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [...]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

const app = Vue.createApp({})
app.use(router)

The documentation has more details.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.