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


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

1. 安裝laravel/ui依賴包

composer require laravel/ui

2.生成vue基本腳手架

php artisan ui vue

系統還提供了非常便捷的auth腳手架,帶登錄注冊。

php artisan ui vue --auth

3.組件位置

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

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

4.在blade模版中使用

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

<!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%E5%A6%82%E4%BD%95%E5%9C%A8blade%E6%96%87%E4%BB%B6%E4%B8%AD%E4%BD%BF%E7%94%A8vue%E7%BB%84%E4%BB%B6


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM