Laravel Framework 11.20.0
@vitejs/[email protected]
vite.config.js:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/js/app.js', 'resources/css/app.css'],
refresh: true,
}),
],
});
app.js:
import { createApp } from 'vue';
const app = createApp({
data() {
return {
message: 'Hello, Vue!'
}
},
template: `
{{ message }}
`
});
app.mount('#app');
welcome.blade.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Laravel with Vue</title>
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body>
<div id="app"></div>
</body>
</html>
error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:5173/@vite/client. (Reason: CORS request did not succeed).
It doesn’t seem like there should be a CORS error for a simple "Hello" app being used to test Laravel together with Vue.
2
Answers
Reference: https://vueschool.io/articles/vuejs-tutorials/the-ultimate-guide-for-using-vue-js-with-laravel/
replace this code in vite.config.js
and replace this @vite([‘resources/css/app.css’, ‘resources/js/app.js’]) with @vite(‘resources/css/app.css’) in welcome.blade.php then check