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=https://www.cnblogs.com/wjcms/p/"{{mix('/css/app.css')}}">
</head>
<body>
<divid="app">
<example-component></example-component>
</divid=>
<script src=https://www.cnblogs.com/wjcms/p/"{{mix('/js/app.js')}}"></script>
</body>
</html>

注意:在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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/53640.html
標籤:JavaScript
