laravel5.7+vue+element-ui配置及简单使用

本文详细介绍了如何在Laravel5.7框架中配置和使用Vue与Element-UI,包括安装步骤、组件测试、路由设置等关键环节。

安装laravel5.7框架

打开终端,输入以下命令

composer create-project laravel/laravel element-ui

这里因为我在上一篇文章中已经新建了一个Nested Set项目,所以我就不再新建了,直接拿来用,有不明白的参考上一篇文章!

安装npm包

cnpm install    //我一般用cnpm,这个是淘宝镜像,国内速度快

安装好后,多出来了一个node_modules文件夹如下图:

node_modules

到这里,其实就可以直接运行项目了,命令:

cnpm run dev

完成后生成了一些编译后的css和js文件,结果如下:

app.js

安装并引入element-ui

安装element-ui

cnpm i element-ui -S

先来测试下Vue组件

打开reresources/js/components目录,我们会看到lavavel自带的一个.vue后缀的example文件:

<template>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card card-default">
                    <div class="card-header">Example Component</div>

                    <div class="card-body">
                        I'm an example component.
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

再继续打开reresources/js/app.js文件观察代码,发现已经引入了example-component组件:

require('./bootstrap');

window.Vue = require('vue');

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

const app = new Vue({
    el: '#app'
});

注意:上面的组件名叫example-component

我们直接新建一个页面来测试下组件吧:

  • 新建「路由-控制器-视图」如下:
//修改web.php,增加一行:
Route::get('/hello','HelloController@index');
  • 创建控制器HelloController.php文件:
php artisan make:controller HelloController
  • 控制器中定义一个index方法,返回视图:
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HelloController extends Controller
{
    public function index()
    {
        return view('hello');
    }
}
  • 创建视图hello.blade.php文件,位于resources/views/目录下,随便写一段简单的代码::
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
    <title>Laravel Vue Element-Ui</title>
</head>
<body>
<div id="app">

    <example-component></example-component>

</div>
<script src="{{ mix('js/app.js') }}"></script>
</body>
</html>

上面增加的两行代码就是引入组件用的:

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

这个时候,你访问 http://nestedset.test/hello 就会看到如下界面:

这说明,你的模板引入成功了。

引入element-ui

现在我们修改resources/js/app.js文件如下:

require('./bootstrap');

window.Vue = require('vue');

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

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

const app = new Vue({
    el: '#app'
});

上面的三行代码就是引入element-ui的,下面我们只要宿便复制一些element-ui组件的代码,放到ExampleComponent.vue文件中就行了,代码如下:

<template>
<div>
<el-row>
  <el-button>默认按钮</el-button>
  <el-button type="primary">主要按钮</el-button>
  <el-button type="success">成功按钮</el-button>
  <el-button type="info">信息按钮</el-button>
  <el-button type="warning">警告按钮</el-button>
  <el-button type="danger">危险按钮</el-button>
</el-row>

<el-row>
  <el-button plain>朴素按钮</el-button>
  <el-button type="primary" plain>主要按钮</el-button>
  <el-button type="success" plain>成功按钮</el-button>
  <el-button type="info" plain>信息按钮</el-button>
  <el-button type="warning" plain>警告按钮</el-button>
  <el-button type="danger" plain>危险按钮</el-button>
</el-row>

<el-row>
  <el-button round>圆角按钮</el-button>
  <el-button type="primary" round>主要按钮</el-button>
  <el-button type="success" round>成功按钮</el-button>
  <el-button type="info" round>信息按钮</el-button>
  <el-button type="warning" round>警告按钮</el-button>
  <el-button type="danger" round>危险按钮</el-button>
</el-row>

<el-row>
  <el-button icon="el-icon-search" circle></el-button>
  <el-button type="primary" icon="el-icon-edit" circle></el-button>
  <el-button type="success" icon="el-icon-check" circle></el-button>
  <el-button type="info" icon="el-icon-message" circle></el-button>
  <el-button type="warning" icon="el-icon-star-off" circle></el-button>
  <el-button type="danger" icon="el-icon-delete" circle></el-button>
</el-row>
</div>
</template>

注意上面的template和div都不能少哦,代码放在这个里面就行了。
然后运行:

cnpm run dev

再打开浏览器,你将看到以下界面:

elemnet-ui

这里有个坑:我用Chrome浏览器怎么刷新都不变,这个时候你要用Shift+刷新才管用!

总结

虽然看起来不难,但是对于没有任何前端基础的人来说,这个坑还需要趟很久吧!
先这样吧,最基础的就是这个教程了,代码我继续传到Github上,自己看吧!
另外:细心的朋友肯定发现了下面的图片:

x-csrf


这个问题就大家自己解决吧!
我的博客:https://leijingwei.com
代码:https://github.com/leienshu/Nested-Set

laravel5.7+vue+element-ui配置及简单使用
Tagged on: element-ui     front-end     laravel     php     vue

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment

Name *

Website

<think>好的,我现在要帮用户找到基于Spring Boot、VueElement-UI和MySQL的智慧民宿在线预订平台源码。首先,我需要回顾用户提供的引用内容,看看有没有相关的项目信息。 用户提到了四个引用,其中引用[4]明确提到“基于springboot+vue的民宿在线预定平台(前后端分离)”,看起来非常符合用户的需求。这个项目由猫头鹰源码博主发布,在优快云上可能有相关资源。用户需要源码下载,可能需要访问博主的页面或联系他们获取。 接下来,我需要考虑用户可能的真实需求。用户可能是一个开发者或者学生,想要搭建类似的平台,需要源码作为参考或基础。因此,除了直接提供下载方式,还应该建议相关的平台如GitHub、Gitee,因为这些地方常有开源项目。 另外,用户提到的其他引用,如引用[3]中的Spring Boot+Vue大学宣讲系统,引用[1]和[2]中的技术栈,虽然相关,但可能不是直接对应的民宿项目。但需要注意是否有其他潜在资源。 需要提醒用户注意源码的版权问题,确保合法使用,特别是商业用途时要遵守许可协议。同时,建议用户查看文档和配置要求,确保环境兼容,比如JDK 1.8、MySQL 5.7等,避免运行时的版本冲突。 如果用户无法找到合适的源码,可能需要建议他们自行开发,并推荐学习资源,比如Spring Boot和Vue的教程,或者考虑定制开发。此外,可以建议在GitHub上用关键词搜索,如“spring boot vue民宿预定”,可能会有相关结果。 总结步骤:1. 直接推荐引用[4]的项目,联系博主获取;2. 建议GitHub、Gitee搜索;3. 检查其他引用是否有帮助;4. 提醒注意事项;5. 备用方案如自行开发或定制。</think>根据您描述的需求,基于Spring Boot+Vue+Element-UI+MySQL的智慧民宿在线预订平台源码可通过以下渠道获取: ### 一、推荐源码来源(直接匹配) 1. **优快云「猫头鹰源码」项目** 在引用[4]中提到的民宿在线预定平台项目,采用前后端分离架构,技术栈完全匹配。建议: - 访问博主优快云主页搜索「民宿在线预定平台」 - 关注文末提供的联系方式获取源码 - 注意该项目包含:在线预订、房源管理、订单支付等民宿核心模块[^4] 2. **GitHub/Gitee开源平台** 可尝试搜索关键词组合: ```bash # 推荐搜索关键词 springboot vue element-ui民宿预定 in:name ``` - 筛选条件:Stars>50、最近更新时间<1年 - 查看项目文档是否包含数据库脚本和部署指南 ### 二、其他可行方案 1. **模块化组合开发** 若找不到完整源码,可参考以下技术实现: - 前端使用Vue+Element-UI实现响应式布局: $$ \text{页面加载速度} \leq 2s \quad (\text{通过Webpack优化实现}) $$ - 后端Spring Boot整合Spring Security JWT实现鉴权[^2] - MySQL表结构设计示例: ```sql CREATE TABLE `homestay` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `geo_location` POINT NOT NULL SRID 4326, -- 地理坐标(GIS扩展) `price_per_night` DECIMAL(10,2) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ``` ### 三、注意事项 1. **源码验证要点** - 检查pom.xml/webpack.config.js确认依赖版本 - 确认包含`db/migration`目录的数据库脚本 - 查看是否集成第三方支付接口(如支付宝沙箱环境) 2. **法律风险规避** - 商业用途需确认源码许可证(建议选择MIT/Apache协议) - 包含人脸识别等敏感功能时需遵守《个人信息保护法》 ### 四、备选建议 若无法获取合适源码,可考虑: 1. 基于Spring Initializr+Vue CLI脚手架新建项目 2. 使用低代码平台(如JeecgBoot)快速生成基础框架 3. 购买商业授权代码(参考阿里云市场/猪八戒网)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值