composer --version |
composer create-project --prefer-dist laravel/laravel blog |
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.16.2",
"bootstrap-sass": "^3.3.7",
"cross-env": "^5.0.1",
"element-ui": "^2.3.7",
"jquery": "^3.1.1",
"laravel-mix": "^1.0",
"lodash": "^4.17.4",
"vue": "^2.1.10",
"vue-router": "^2.4.0",
"qs": "^6.5.2"
}
}
|
cnpm install |
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
//加入需要渲染的页面
import Home from '../components/Home'
import Index from '../components/Index'
import Bar from '../components/Bar'
import Foo from '../components/Foo'
import Role from '../components/Role'
import Not_Found from '../components/Not_Found'
Vue.use(VueRouter);
const routes=[
{
path: '/',
component: Home,
children:[
{
path: '/',
name: 'index',
component: Index
},
{
path: 'index',
name: 'goindex',
redirect: '/'
},
{
path: 'bar',
name: 'bar',
component: Bar
},
{
path: 'foo',
name: 'foo',
component: Foo,
},
{
path: 'role',
name: 'rolw',
component: Role,
},
{
path: '404',
name: '404',
component: Not_Found
},
{
path: '*',
name: 'to404',
redirect: '/404'
},
]
},
{
path: '*',
name: 'go404',
redirect: '/404'
}
];
const router = new VueRouter({
routes: routes,
// mode: 'history'
});
router.push('/index'); //一进入就跳到该路由
export default router
|
|
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./bootstrap');
window.Vue = require('vue');
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
import App from './App.vue'
import router from './router'
import Axios from "axios"
import qs from 'qs'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.prototype.$axios = Axios
Vue.use(ElementUI)
const app = new Vue({
el: '#app',
router,
render: h => h(App)
});
|
@select="handleSelect" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b">
我的工作台
选项4
{{name}}
export default {
data() {
return {
activeIndex: '1',
activeIndex2: '1',
name : '时间旅者'
};
},
methods: {
handleSelect(key, keyPath) {
window.location.href = location.origin + "/#" + key;
console.log(key,keyPath);
},
logout(){
console.log("logout");
}
}
}
|
import Header from "./Header"
export default {
data() {
return {
};
},
components:{
Header,
}
}
|
export default {
name:"foo",
data(){
return {
imgs: [
{
key:1,
path:"/images/myimg/1.jpg"
},
{
key:2,
path:"/images/myimg/2.jpg"
},
{
key:3,
path:"/images/myimg/3.jpg"
},
{
key:4,
path:"/images/myimg/4.jpg"
},
{
key:5,
path:"/images/myimg/5.jpg"
},
{
key:6,
path:"/images/myimg/6.jpg"
},
]
}
}
}
.el-carousel__item:nth-child(2n) {
background-color: #99a9bf;
text-align: center;
}
.el-carousel__item:nth-child(2n+1) {
background-color: #d3dce6;
text-align: center;
}
|
:data="tableData"
border
height="540"
style="width: 100%">
fixed
prop="id"
label="编号"
width="80">
fixed
prop="date"
label="日期"
width="150">
prop="name"
label="姓名"
width="150">
prop="province"
label="省份"
width="150">
prop="city"
label="市区"
width="150">
prop="address"
label="地址"
width="350">
prop="zip"
label="邮编"
width="150">
fixed="right"
label="操作"
width="150">
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[10, 20, 50, 100]"
:page-size="pagesize"
layout="total, sizes, prev, pager, next, jumper"
:total="total">
title="提示"
:visible.sync="dialogVisible"
width="30%"
:before-close="handleClose" >
日期:{{ gridData.date }}
姓名:{{ gridData.name }}
省份:{{ gridData.province }}
市区:{{ gridData.city }}
地址:{{ gridData.address }}
邮编:{{ gridData.zip }}
export default {
data() {
return {
pagesize: 10,
currentPage: 1,
total: 0,
tableData: [],
gridData:{},
dialogVisible : false,
}
},
methods:{
getData:function(){
this.$axios("/getData",{
params:{
pagesize:this.pagesize,
currentPage:this.currentPage
}
})
.then(function(res) {
this.tableData = res.data.data;
this.total = res.data.total;
console.log(this.tableData);
}.bind(this))
.catch(function(error){
console.log(error);
})
},
showDetail:function(row) {
this.gridData = {
address:row.address,
city:row.city,
date:row.date,
name:row.name,
province:row.province,
zip:row.zip,
};
this.dialogVisible = true;
},
handleSizeChange: function (size) {
this.pagesize = size;
this.getData();
},
handleCurrentChange: function(currentPage){
this.currentPage = currentPage;
this.getData();
},
handleClose:function(done) {
this.$confirm('确认关闭?')
.then(_ => {
done();
})
.catch(_ => {});
}
},
created:function(){
this.getData();
}
}
.el-pagination{
text-align: center;
}
|
时间范围选择
v-model="value5"
type="datetimerange"
:picker-options="pickerOptions2"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
align="right">
您选择的时间范围为:{{ value5[0] }} 至 {{ value5[1] }}
export default {
data() {
return {
pickerOptions2: {
shortcuts: [{
text: '最近一周',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一个月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近三个月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
picker.$emit('pick', [start, end]);
}
}]
},
value5: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
};
}
};
.block{
height: 500px;
}
|
定时任务补偿
import Index from "./Index"
import Bar from "./Bar"
import Role from "./Role"
export default {
name:"foo",
data(){
return {
msg: "我是foo组件"
}
},
components:{
Index,
Bar,
Role
}
}
|
namespace App;
class DataFrom
{
public $id;
public $date;
public $name;
public $province;
public $city;
public $address;
public $zip;
}
|
php artisan make:controller UserController |
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use App\DataFrom;
class UserController extends Controller
{
public function getData(Request $request){
//生成数据并进行分页传给前端
$arr = [];
for($i=1;$i<1002;$i++){
$dataFrom = new DataFrom();
$dataFrom->id = $i;
$dataFrom->date = '2016-05-0'.$i;
$dataFrom->name = '王小虎'.$i;
$dataFrom->province = '上海'.$i;
$dataFrom->city = '普陀区'.$i;
$dataFrom->address = '上海市普陀区金沙江路 1518 弄'.$i;
$dataFrom->zip = '20033'.$i;
$arr[] = $dataFrom;
}
$currentPage = $request->input('currentPage', 1); // 获取页码
$pagesize = $request->input('pagesize', 10); //每页的条数
$offset = ($currentPage * $pagesize) - $pagesize;//计算每页分页的初始位置
$res = new LengthAwarePaginator(array_slice($arr,$offset,$pagesize,true),count($arr),$pagesize,
$currentPage,['path' => $request->url(), 'query' => $request->query()]);
return response()->json($res);
}
}
|
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome'); //主视图
});
Route::get('
/getData
', '
UserController@getData
');
|
|
cnpm run dev |
npm run watch |
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
.extract(['vue','axios']);
|
文件
|
说明
|
public/js/manifest.js
|
Webpack manifest runtime
|
public/js/vendor.js
|
vendor 库
|
public/js/app.js
|
应用代码
|
|
npm run watch |