[英]laravel 9 + Vue.js 2 And Vite im facing error
I'm new in laravel 9 and vite my old project im using laravel 7 with laravel/UI vue.js 2 for my project now im using laravel 9 and vue.js 2 and vite for my project im developed as my old style in used in laravel 7, but im facing some error IN LARAVEL 9 WITH VITE. I'm new in laravel 9 and vite my old project im using laravel 7 with laravel/UI vue.js 2 for my project now im using laravel 9 and vue.js 2 and vite for my project im developed as my old style in used in laravel 7,但我在 LARAVEL 9 WITH VITE 中遇到了一些错误。 ERROR
错误
Cannot set properties of undefined (setting 'id')
无法设置未定义的属性(设置“id”)
MY PROJECT CODE APP.VUE我的项目代码APP.VUE
require('./bootstrap');
import {Vue} from "vue";
import router from "./router";
window.Vue = require('vue');
const app = new Vue({
el: '#app',
router,
});
ROUTER路由器
import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
// MainComponents
import Home from "./components/MainComponents/Home.vue";
const routes = [
//Admin Login
{
path: "/",
name: "Home",
component: Home,
},
];
const router = new VueRouter({
routes,
mode: "history",
});
export default router;
WELCOME.BLADE.PHP WELCOME.BLADE.PHP
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HELLO</title>
@vite('resources/css/app.css')
</head>
<body>
<div id="app">
<router-view></router-view>
</div>
@vite('resources/js/app.js')
</body>
</html>
WEB.PHP WEB.PHP
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
Route::get('{any}', function () {
return view('welcome');
})->where('any', '.*');
COMPONENT零件
<template>
<div >
MAIN PAGE COMPONENT
</div>
</template>
vite.config.js vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/sass/app.scss',
'resources/js/app.js',
],
refresh: true,
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
],
resolve: {
alias: {
vue: 'vue/dist/vue.esm-bundler.js',
},
},
});
First things first, it is not really practical to use require
in vite project, but if you do, you have to either use a plugin or manually work around it.首先,在 vite 项目中使用
require
并不实际,但如果你这样做,你必须使用插件或手动解决它。 Does the id error comes from the vite file itself or from your code? id 错误是来自 vite 文件本身还是来自您的代码?
If you still haven't succeeded, I recommend you check this link vite with laravel如果您仍然没有成功,我建议您使用 laravel 检查此链接 vite
And use vite-plugin-vue2
并使用
vite-plugin-vue2
If so, please share如果有,请分享
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.