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

相关文章
相关标签/搜索