我正在使用 laravel 8
现在我想安装 Vue.js
.我正在尝试这样
composer require laravel/ui
php artisan ui vue
php artisan ui vue --auth
最佳答案
更新:如果您想完全避免 Laravel ^8.0 应用程序中的 Inertia/Livewire (Alpine.js) 脚手架并使用 Vue - 安装 Laravel UI ,这很可能会无限期地保持下去。
在 Laravel 应用程序中安装 Vue(和旧的身份验证脚手架)的说明:
composer require laravel/ui
php artisan ui vue
仅用于安装 Vue。 php artisan ui vue --auth
用于搭建 auth View 。 npm install && npm run dev
但是,如果您仍然想使用
Vue.js
与 Livewire
脚手架,请使用以下说明。 重要提示:请注意
Vue.js
一旦安装,就控制 DOM,分离节点并替换它,删除其他 JS 监听器。因此,如果您在 Vue 的同一页面上使用 Livewire,Alpine.js
附带 Livewire
脚手架不起作用。作为解决方法,您可以使用 Livewire VueJS support plugin. npm install --save vue
window.Vue = require('vue');
Vue.component('example-component', require('./components/ExampleComponent.vue').default);
const app = new Vue({
el: '#app',
});
<template>
<div>Hello World.</div>
</template>
<script>
export default {
mounted() {
console.log("Example component mounted");
}
};
</script>
<script src="{{ asset('js/app.js') }}" defer></script>
在 <head>
布局文件的一部分 ( resources/views/layouts/app.blade.php
)id="app"
至 <body>
或主要 <div>
在您的布局文件中 ( resources/views/layouts/app.blade.php
)<example-component />
你的看法npm run dev
或 npm run watch
Example component mounted
关于vue.js - 如何在 Laravel 8 中安装 Vue.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63853750/