Laravel9 与 Vue2
我使用命令
laravel new blog
writer require laravel/ui
php artisan ui vue
npm install vue-router
npm install
app.js
window.Vue = require('vue').default;
import router from "./router/router";
const app = new Vue({
el: '#app',
router
});
router/router.js
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'Home',
component: () => import('../components/ExampleComponent.vue')
}
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
export default router
安装了 Laravel 和 Vuejs它给出了当我执行这个命令时出现错误 npm 运行手表
export 'default' (imported as 'VueRouter') was not found in 'vue-router' (possible exports: NavigationFailureType, RouterLink, RouterView, START_LOCATION, createMemoryHistory, createRouter, createRouterMatcher, createWebHashHistory, createWebHistory, isNavigationFailure, matchedRouteKey, onBeforeRouteLeave, onBeforeRouteUpdate, parseQuery, routeLocationKey, routerKey, routerViewLocationKey, stringifyQuery, useLink, useRoute, useRouter, viewDepthKey)
WARNING in ./resources/js/router/router.js 11:17-26
export 'default' (imported as 'VueRouter') was not found in 'vue-router' (possible exports: NavigationFailureType, RouterLink, RouterView, START_LOCATION, createMemoryHistory, createRouter, createRouterMatcher, createWebHashHistory, createWebHistory, isNavigationFailure, matchedRouteKey, onBeforeRouteLeave, onBeforeRouteUpdate, parseQuery, routeLocationKey, routerKey, routerViewLocationKey, stringifyQuery, useLink, useRoute, useRouter, viewDepthKey)
WARNING in ./resources/js/components/ExampleComponent.vue?vue&type=template&id=299e239e (./node_modules/babel-loader/lib/index.js??clonedRuleSet-5.use[0]!../node_modules/vue-loader/dist/templateLoader.js??ruleSet[1].rules[2]!../node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./resources/js/components/ExampleComponent.vue?vue&type=template&id=299e239e) 6:30-48
export 'createStaticVNode' (imported as '_createStaticVNode') was not found in 'vue' (possible exports: default)
WARNING in ./resources/js/components/ExampleComponent.vue?vue&type=template&id=299e239e (./node_modules/babel-loader/lib/index.js??clonedRuleSet-5.use[0]!../node_modules/vue-loader/dist/templateLoader.js??ruleSet[1].rules[2]!../node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./resources/js/components/ExampleComponent.vue?vue&type=template&id=299e239e) 10:9-19
export 'openBlock' (imported as '_openBlock') was not found in 'vue' (possible exports: default)
WARNING in ./resources/js/components/ExampleComponent.vue?vue&type=template&id=299e239e (./node_modules/babel-loader/lib/index.js??clonedRuleSet-5.use[0]!../node_modules/vue-loader/dist/templateLoader.js??ruleSet[1].rules[2]!../node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./resources/js/components/ExampleComponent.vue?vue&type=template&id=299e239e) 10:23-42
export 'createElementBlock' (imported as '_createElementBlock') was not found in 'vue' (possible exports: default)
WARNING in ./node_modules/vue-router/dist/vue-router.esm-bundler.js 1852:4-15
export 'onUnmounted' (imported as 'onUnmounted') was not found in 'vue' (possible exports: default)
WARNING in ./node_modules/vue-router/dist/vue-router.esm-bundler.js 1853:4-17
export 'onDeactivated' (imported as 'onDeactivated') was not found in 'vue' (possible exports: default)
WARNING in ./node_modules/vue-router/dist/vue-router.esm-bundler.js 1854:4-15
export 'onActivated' (imported as 'onActivated') was not found in 'vue' (possible exports: default)
WARNING in ./node_modules/vue-router/dist/vue-router.esm-bundler.js 1867:52-70
export 'getCurrentInstance' (imported as 'getCurrentInstance') was not found in 'vue' (possible exports: default)
WARNING in ./node_modules/vue-router/dist/vue-router.esm-bundler.js 1871:25-31
export 'inject' (imported as 'inject') was not found in 'vue' (possible exports: default)```
I installed Laravel and Vuejs with commands
laravel new blog
composer require laravel/ui
php artisan ui vue
npm install vue-router
npm install
app.js
window.Vue = require('vue').default;
import router from "./router/router";
const app = new Vue({
el: '#app',
router
});
router/router.js
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'Home',
component: () => import('../components/ExampleComponent.vue')
}
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
export default router
It gives an error when I execute this command
npm run watch
export 'default' (imported as 'VueRouter') was not found in 'vue-router' (possible exports: NavigationFailureType, RouterLink, RouterView, START_LOCATION, createMemoryHistory, createRouter, createRouterMatcher, createWebHashHistory, createWebHistory, isNavigationFailure, matchedRouteKey, onBeforeRouteLeave, onBeforeRouteUpdate, parseQuery, routeLocationKey, routerKey, routerViewLocationKey, stringifyQuery, useLink, useRoute, useRouter, viewDepthKey)
WARNING in ./resources/js/router/router.js 11:17-26
export 'default' (imported as 'VueRouter') was not found in 'vue-router' (possible exports: NavigationFailureType, RouterLink, RouterView, START_LOCATION, createMemoryHistory, createRouter, createRouterMatcher, createWebHashHistory, createWebHistory, isNavigationFailure, matchedRouteKey, onBeforeRouteLeave, onBeforeRouteUpdate, parseQuery, routeLocationKey, routerKey, routerViewLocationKey, stringifyQuery, useLink, useRoute, useRouter, viewDepthKey)
WARNING in ./resources/js/components/ExampleComponent.vue?vue&type=template&id=299e239e (./node_modules/babel-loader/lib/index.js??clonedRuleSet-5.use[0]!../node_modules/vue-loader/dist/templateLoader.js??ruleSet[1].rules[2]!../node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./resources/js/components/ExampleComponent.vue?vue&type=template&id=299e239e) 6:30-48
export 'createStaticVNode' (imported as '_createStaticVNode') was not found in 'vue' (possible exports: default)
WARNING in ./resources/js/components/ExampleComponent.vue?vue&type=template&id=299e239e (./node_modules/babel-loader/lib/index.js??clonedRuleSet-5.use[0]!../node_modules/vue-loader/dist/templateLoader.js??ruleSet[1].rules[2]!../node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./resources/js/components/ExampleComponent.vue?vue&type=template&id=299e239e) 10:9-19
export 'openBlock' (imported as '_openBlock') was not found in 'vue' (possible exports: default)
WARNING in ./resources/js/components/ExampleComponent.vue?vue&type=template&id=299e239e (./node_modules/babel-loader/lib/index.js??clonedRuleSet-5.use[0]!../node_modules/vue-loader/dist/templateLoader.js??ruleSet[1].rules[2]!../node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./resources/js/components/ExampleComponent.vue?vue&type=template&id=299e239e) 10:23-42
export 'createElementBlock' (imported as '_createElementBlock') was not found in 'vue' (possible exports: default)
WARNING in ./node_modules/vue-router/dist/vue-router.esm-bundler.js 1852:4-15
export 'onUnmounted' (imported as 'onUnmounted') was not found in 'vue' (possible exports: default)
WARNING in ./node_modules/vue-router/dist/vue-router.esm-bundler.js 1853:4-17
export 'onDeactivated' (imported as 'onDeactivated') was not found in 'vue' (possible exports: default)
WARNING in ./node_modules/vue-router/dist/vue-router.esm-bundler.js 1854:4-15
export 'onActivated' (imported as 'onActivated') was not found in 'vue' (possible exports: default)
WARNING in ./node_modules/vue-router/dist/vue-router.esm-bundler.js 1867:52-70
export 'getCurrentInstance' (imported as 'getCurrentInstance') was not found in 'vue' (possible exports: default)
WARNING in ./node_modules/vue-router/dist/vue-router.esm-bundler.js 1871:25-31
export 'inject' (imported as 'inject') was not found in 'vue' (possible exports: default)```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您安装了与 vue2 不兼容的依赖项。
尝试更改
vue-router
和vuex
版本。尝试安装以下版本 -
You have installed incompatible dependencies for vue2.
Try changing
vue-router
andvuex
versions.Try installing the following versions -
@quadmachine
package.josn
@quadmachine
package.josn