Laravel7如何使用Vue前端框架,本篇文章手把手一起学

作者: 温新

分类: 【Laravel】

阅读: 2629

时间: 2020-06-01 14:35:00

此篇学习记录是基础上一篇文章,因此,对于本篇学习记录有所不理解的地方,需要回头看看 Laravel7使用前端脚手架 这个文章。

==========================================================================================================================================================================================================================

下面直接进入主题,Laravel7使用Vue组件。

第一步、新建Vue组件并编写内容

// app/resources/js/components/WelcomeComponent.vue


<template>
    <div class="flex-center position-ref full-height">
        <div class="content">
            <div class="title m-b-md">
                Laravel
            </div>

            <div class="links">
                <a href="https://www.ziruchu.com/cat/1">原创文学</a>
                <a href="https://www.ziruchu.com/cat/5">PHP</a>
                <a href="https://www.ziruchu.com/cat/10">Laravel</a>
                <a href="https://www.ziruchu.com/cat/11">ThinkPHP</a>
                <a href="https://www.ziruchu.com/cat/15">数据库</a>
                <a href="https://www.ziruchu.com/cat/19">Linux</a>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "WelcomeComponent"
    }
</script>

<style scoped>
    html, body {
        background-color: #fff;
        color: #636b6f;
        font-family: 'Nunito', sans-serif;
        font-weight: 200;
        height: 100vh;
        margin: 0;
    }

    .full-height {
        height: 100vh;
    }

    .flex-center {
        align-items: center;
        display: flex;
        justify-content: center;
    }

    .position-ref {
        position: relative;
    }

    .top-right {
        position: absolute;
        right: 10px;
        top: 18px;
    }

    .content {
        text-align: center;
    }

    .title {
        font-size: 84px;
    }

    .links > a {
        color: #636b6f;
        padding: 0 25px;
        font-size: 12px;
        font-weight: 600;
        letter-spacing: .1rem;
        text-decoration: none;
        text-transform: uppercase;
    }

    .m-b-md {
        margin-bottom: 30px;
    }
</style>

第二步、注册vue组件

// app/resources/js/app.js
Vue.component(
    'welcome-component', 
    require('./components/WelcomeComponent.vue').default
);

第三步、文件中使用vue组件

// app/resources/welcome.blade.php

<!--注意,我省略了一些html代码,只留下了body内的内容-->
<!-- 下面的内容放在body内-->    
<div id="app">
    <welcome-component></welcome-component>
    <example-component></example-component>
</div>

<script src="{{ asset('js/app.js')  }}"></script>

第四步、编译运行

npm run dev

<!--或者监听-->

npm run watch

1591021553(1).jpg

^_^完

关于技术问题,欢迎大家一起来学习,分享学习知识,共同前进!

我是夕阳何处寻,期待和优秀的你一起同行!

夕阳何处寻

2020年06月01日

请登录后再评论