import Vue from "vue"; import { createRouter, createWebHistory } from "vue-router";…
- User
import Vue from "vue"; import { createRouter, createWebHistory } from "vue-router"; import pageBlog from "../pages/pageBlog.vue"; import App from "../App.vue";
Vue.use(createRouter); Vue.use(createWebHistory);
const routes = [ { path: "/", name: "App", component: App }, { path: "/pageBlog", name: "pageBlog", component: pageBlog } ];
const router = new VueRouter({ mode: "history", base: process.env.BASE_URL, routes });
export default router;
Use /* eslint-disable */ to ignore all warnings in a file. ERROR in [eslint] C:\Users\Console\Desktop\vuejs\blog\src\router\router.js 22:20 error 'VueRouter' is not defined no-undef
✖ 1 problem (1 error, 0 warnings)
webpack compiled with 1 error
- Assistant
It looks like you are trying to import and use the Vue Router in a Vue project. However, there are a few issues in your code.
First, you need to import
createRouterandcreateWebHistoryindividually, not with theVue.use()syntax. So you should replace the following lines:Vue.use(createRouter); Vue.use(createWebHistory);with:
import { createRouter, createWebHistory } from "vue-router";Second, when creating the
new VueRouter()instance, you need to use as an argument, not . So you should replace the following line: - User
Cannot read properties of undefined (reading 'use') TypeError: Cannot read properties of undefined (reading 'use') at eval (webpack-internal:///./src/store/index.js:6:45) at ./src/store/index.js (http://localhost:8080/js/app.js:107:1) at webpack_require (http://localhost:8080/js/app.js:288:33) at fn (http://localhost:8080/js/app.js:522:21) at eval (webpack-internal:///./src/main.js:4:68) at ./src/main.js (http://localhost:8080/js/app.js:85:1) at webpack_require (http://localhost:8080/js/app.js:288:33) at http://localhost:8080/js/app.js:1410:109 at webpack_require.O (http://localhost:8080/js/app.js:334:23) at http://localhost:8080/js/app.js:1411:53 ما حل هذه المشكلة
- Assistant
هذا الخطأ يشير إلى أنك تحاول استخدام الدالة
use()في كائن غير معرف. من الواضح أن الخطأ يحدث في ملفindex.jsفي مجلدstoreالخاص بك.لحل هذه المشكلة، هناك افتراضين محتملين:
-
إذا كنت تحاول استخدام Vue Router في ملف
index.jsفي مجلدstore، فيجب عليك نقل استدعاءuse()إلى ملفmain.jsأو ملف الإدخال الرئيسي الخاص بتطبيقك. وذلك لأنه يجب تثبيت Vue Router في عنصرAppالجذري وليس في التخزين. -
إذا لم تكن تستخدم Vue Router في تطبيقك ولكن الخطأ يحدث في ملف
index.jsفي مجلدstore، فيجب التحقق مما إذا كنت قد قمت بتثبيت Vuex بشكل صحيح أو لا. Vuex هو حزمة لإدارة الحالة في تطبيقات Vue ولا يتطلب استخدام الدالةuse().
يمكن أن يكون الحل المناسب حسب حالتك ونوع تطبيقك. إذا كنت بحاجة إلى مزيد من المساعدة، يرجى تزويدنا بمزيد من التفاصيل حول تكوين تطبيقك وأماكن استدعاء الدالة
use(). -
- User
import Vue from "vue"; import Vuex from "vuex";
Vue.use(Vuex);
const store = new Vuex.Store({ state: { token: "", isAuthenticated: localStorage.getItem("Token") || false, Authentication: localStorage.getItem("Token") || null }, getters: { isAuthenticated(state) { return state.isAuthenticated; }, Authentication(state) { return state.Authentication; } }, mutations: { initializeStore(state) { if (localStorage.getItem("Token")) { state.token = localStorage.getItem("Token"); state.isAuthenticated = true; } else { state.token = ""; state.isAuthenticated = false; } }, setToken(state, token) { state.token = token; state.Authentication = token; state.isAuthenticated = true; }, removeToken(state) { state.token = ""; state.isAuthenticated = false; } }, actions: {
}, modules: {}}); export default store Cannot read properties of undefined (reading 'use') TypeError: Cannot read properties of undefined (reading 'use') at eval (webpack-internal:///./src/store/index.js:6:45) at ./src/store/index.js () at () at fn () at eval (webpack-internal:///./src/main.js:4:77) at ./src/main.js () at () at at .O () at
- Assistant
الخطأ يشير إلى أنك تحاول استخدام
Vue.use()قبل استيراد Vuex. يجب أن تستدعي "vuex" وتستخدمه في Vue قبل استدعاءVue.use().لحل هذه المشكلة، قم بتعديل ملف
index.jsفي مجلدstoreالخاص بك على النحو التالي:import Vue from "vue"; import Vuex from "vuex"; Vue.use(Vuex); const store = new Vuex.Store({ // تعريف الحالة والمتغيرات والمتحولات الأخرى هنا // ... }); export default store;تأكد من أنك قد قمت بتثبيت حزمة Vuex من خلال تنفيذ الأمر
npm install vuexفي مجلد المشروع الخاص بك. أيضًا ، تأكد من أن لديك نسخة حديثة من Vue و Vuex. يمكنك التحقق من الإصدارات المثبتة في ملف package.json الخاص بمشروعك. بعد ذلك، قم بإعادة تشغيل تطبيقك ويجب أن تتمكن من استخدام Vuex بدون أي أخطاء. - User
import { createRouter, createWebHistory } from "vue-router"; import pageBlog from "../pages/pageBlog.vue"; import App from "../App.vue";
- Assistant
الخطأ يحدث لأنك تستدعي ملف التخزين (
store) قبل استيراد Vue. لذلك، Vue ليست معرفة حينما يتم استخدامuse()في Vuex.لحل المشكلة، قم بتغيير الترتيب في ملف
main.jsعلى النحو التالي:import { createApp } from "vue"; import router from "../src/router/router.js"; import store from "../src/store/index.js"; import App from "./App.vue"; const app = createApp(App); app.use(store); app.use(router); app.mount("#app");بهذا الترتيب، Vue سيكون معرفًا عند استخدام
use()في Vuex.قد توجد مشاكل أخرى تتعلق بتكوين التطبيق الخاص بك. يمكنك التحقق من استيراداتك ومخطط Vue الخاص بك في ملف
App.vueوالتأكد من أن جميع المكونات المستخدمة تم استيرادها بشكل صحيح.