Laravel 如何在blade文件中使用Vue組件

Laravel 如何在blade文件中使用Vue組件php

1. 安裝laravel/ui依賴包

composer require laravel/ui

2.生成vue基本腳手架

php artisan ui react

系統還提供了很是便捷的auth腳手架,帶登陸註冊。css

php artisan ui react --auth

3.組件位置

Vue組件ExampleComponent.vue將被放置在resources/js/components目錄中。ExampleComponent.vue文件是單個文件Vue組件的示例,該組件在同一文件中定義其JavaScript和HTML模板。單個文件組件爲構建JavaScript驅動的應用程序提供了一種很是方便的方法。該示例組件已在您的app.js文件中註冊:html

Vue.component(
    'example-component',
    require('./components/ExampleComponent.vue').default
);

4.在blade模版中使用

要在應用程序中使用該組件,您能夠將該組件放入Blade模板xxx.blade.php中:vue

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>@yield('title')</title>
    <link rel="stylesheet" href="{{mix('/css/app.css')}}">
</head>

<body>
    <divid="app">
        <example-component></example-component>
    </divid=>
    <script src="{{mix('/js/app.js')}}"></script>
</body>

</html>

file

注意:在blade文件中必定要有id爲app的根節點,並且把組件放到裏面,才能生效!!!

轉自:https://www.wjcms.net/archives/laravel如何在blade文件中使用vue組件react

本文由博客一文多發平臺 OpenWrite 發佈!laravel

相關文章
相關標籤/搜索