最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

laravel5.4+vue+element簡(jiǎn)單搭建的示例代碼

 更新時(shí)間:2017年08月29日 10:55:39   作者:sangjinchao  
本篇文章主要介紹了laravel5.4+vue+element簡(jiǎn)單搭建的示例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

如今laravel來(lái)到5.4版本,更方便引入vue了,具體步驟如下:

1.下載laravel5.4,這邊是下載地址(里面的配置文件都寫(xiě)得差不多了)!

2.打開(kāi)package.json

內(nèi)容如下 

{ 
 "private": true, 
 "scripts": { 
  "dev": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 
  "watch": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 
  "hot": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", 
  "production": "node node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" 
 }, 
 "devDependencies": { 
  "axios": "^0.15.2", 
  "bootstrap-sass": "^3.3.7", 
  "jquery": "^3.1.0", 
  "laravel-mix": "^0.6.0", 
  "lodash": "^4.16.2", 
  "vue": "^2.0.1" 
 } 
} 

修改一下

{ 
 "private": true, 
 "scripts": { 
  "dev": "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-en NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 
  "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", 
  "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.15.3", 
  "bootstrap-sass": "^3.3.7", 
  "jquery": "^3.1.1", 
  "laravel-mix": "^0.8.3", 
  "cross-env": "^3.2.3", 
  "lodash": "^4.17.4", 
  "vue": "^2.1.10", 
  "element-ui": "^1.2.8", 
  "vue-loader": "^11.3.4", 
  "vue-router": "^2.4.0" 
 } 
} 

修改的地方看清楚哦

lodash的版本改為^4.17.4,否則編譯會(huì)出錯(cuò),請(qǐng)注意紅色字體

laravel5.4的mix挺好用,建議大家去看一下,這是地址

3.在根目錄運(yùn)行 cnpm install

注意是cnpm,尤其是windows用戶,不然將會(huì)報(bào)錯(cuò)

4.然后修改resources/assets/js/bootstrap.js

30多行有

復(fù)制代碼 代碼如下:

window.axios.defaults.headers.common = {    'X-CSRF-TOKEN': .......,    'X-Requested-With': 'XMLHttpRequest'};

把'X-CSRF-TOKEN'這一項(xiàng)改為

復(fù)制代碼 代碼如下:

'X-CSRF-TOKEN': document.querySelector('meta[name="X-CSRF-TOKEN"]').content,

否則,不能成功獲取csrf

5.修改resources/assets/js/app.js

這里簡(jiǎn)單測(cè)試一下,并沒(méi)有引入element

/** 
 * 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'); 
 
/** 
 * 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 "./components/Example.vue" 
 
const app = new Vue({ 
  el: '#app', 
  render: h => h(App) 
}); 

6.修改resources/views/welcome.blade.php

<!DOCTYPE html> 
<html lang="{{ config('app.locale') }}"> 
<head> 
  <meta charset="utf-8"> 
  <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <meta name="X-CSRF-TOKEN" content="{{csrf_token()}}"> 
  <title>123</title> 
</head> 
<body> 
<div id="app"></div> 
 
<script src="{{ mix('js/app.js') }}"></script> 
</body> 
</html> 

然后運(yùn)行npm run watch

這就簡(jiǎn)單搭建成功了

第二種方法,沒(méi)有用到mix

下圖為我動(dòng)到的文件

1.下載laravel5.4

2.命令行(laravel5.4目錄下):composer install

3.新建.env文件,把.env.example里的內(nèi)容復(fù)制到.env文件中

4.生成key,命令行:PHP artisan key:generate

5.配置文件package.json,內(nèi)容如下:

{ 
 "private": true, 
 "scripts": { 
  "prod": "gulp --production", 
  "dev": "gulp watch" 
 }, 
 "devDependencies": { 
  "babel-core": "^6.20.0", 
  "babel-loader": "^6.2.9", 
  "css-loader": "^0.25.0", 
  "element-ui": "^1.1.1", 
  "gulp": "^3.9.1", 
  "handsontable": "0.27.0", 
  "laravel-elixir": "^6.0.0-15", 
  "laravel-elixir-vue-2": "^0.2.0", 
  "laravel-elixir-webpack-official": "^1.0.10", 
  "style-loader": "^0.13.1", 
  "vue": "^2.1.4", 
  "vue-loader": "^10.0.0", 
  "vue-resource": "^1.0.3", 
  "vue-router": "^2.1.1", 
  "vue-template-compiler": "^2.1.4", 
  "axios": "^0.15.2", 
  "bootstrap-sass": "^3.3.7", 
  "jquery": "^3.1.0", 
  "laravel-mix": "^0.5.0", 
  "lodash": "^4.16.2" 
 }, 
 "dependencies": {} 
}

6.命令行(沒(méi)有npm的自行下載):npm install

7.resources/assets/js下新建App.vue文件,內(nèi)容如下:

<template> 
 <div id="app"> 
  <router-view></router-view> 
 </div> 
</template>

8.resources/assets/js/app.js

/** 
 * 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'); 
/** 
 * 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 VueRouter from 'vue-router' 
import ElementUI from 'element-ui' 
import 'element-ui/lib/theme-default/index.css' 
 
Vue.use(VueRouter) 
Vue.use(ElementUI) 
 
 
const router = new VueRouter({ 
 routes: [ 
  { path: '/', component: require('./components/Example.vue') } 
 ] 
}) 
 
const app = new Vue({ 
  el: '#app', 
  router, 
  template: '<App/>', 
  components: { App } 
});

9.把resources/view/welcome.blade.php改為:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
 <meta charset="UTF-8"> 
 <title>Hello</title> 
</head> 
<body> 
<div id="app"></div> 
 
<script src="{{ asset('js/app.js') }}"></script> 
</body> 
</html> 

10.在主目錄下新建gulpfile.js文件,內(nèi)容:

const elixir = require('laravel-elixir'); 
const path = require('path'); 
 
require('laravel-elixir-vue-2'); 
/* 
 |-------------------------------------------------------------------------- 
 | Elixir Asset Management 
 |-------------------------------------------------------------------------- 
 | 
 | Elixir provides a clean, fluent API for defining some basic Gulp tasks 
 | for your Laravel application. By default, we are compiling the Sass 
 | file for our application, as well as publishing vendor resources. 
 | 
 */ 
 
elixir(mix => { 
  // Elixir.webpack.config.module.loaders = []; 
 
  Elixir.webpack.mergeConfig({ 
    resolveLoader: { 
      root: path.join(__dirname, 'node_modules'), 
    }, 
    module: { 
      loaders: [ 
        { 
          test: /\.css$/, 
          loader: 'style!css' 
        } 
      ] 
    } 
  }); 
 
  mix.sass('app.scss') 
    .webpack('app.js') 
}); 

11.命令行(沒(méi)有g(shù)ulp,自行下載):gulp watch

這樣就簡(jiǎn)單的搭建完成了,可以訪問(wèn)了!

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Element UI框架中巧用樹(shù)選擇器的實(shí)現(xiàn)

    Element UI框架中巧用樹(shù)選擇器的實(shí)現(xiàn)

    這篇文章主要介紹了Element UI框架中巧用樹(shù)選擇器的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • 在vue中使用rules對(duì)表單字段進(jìn)行驗(yàn)證方式

    在vue中使用rules對(duì)表單字段進(jìn)行驗(yàn)證方式

    這篇文章主要介紹了在vue中使用rules對(duì)表單字段進(jìn)行驗(yàn)證方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • vue3如何實(shí)現(xiàn)錨點(diǎn)定位點(diǎn)擊滾動(dòng)高亮

    vue3如何實(shí)現(xiàn)錨點(diǎn)定位點(diǎn)擊滾動(dòng)高亮

    這篇文章主要介紹了vue3如何實(shí)現(xiàn)錨點(diǎn)定位點(diǎn)擊滾動(dòng)高亮問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • vue項(xiàng)目中data數(shù)據(jù)之間互相訪問(wèn)的實(shí)現(xiàn)

    vue項(xiàng)目中data數(shù)據(jù)之間互相訪問(wèn)的實(shí)現(xiàn)

    本文主要介紹了vue項(xiàng)目中data數(shù)據(jù)之間互相訪問(wèn)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05
  • vue組件實(shí)現(xiàn)發(fā)表評(píng)論功能

    vue組件實(shí)現(xiàn)發(fā)表評(píng)論功能

    這篇文章主要為大家詳細(xì)介紹了vue組件實(shí)現(xiàn)發(fā)表評(píng)論功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • vue bus全局事件中心簡(jiǎn)單Demo詳解

    vue bus全局事件中心簡(jiǎn)單Demo詳解

    ue-bus 提供了一個(gè)全局事件中心,并將其注入每一個(gè)組件,你可以像使用內(nèi)置事件流一樣方便的使用全局事件。這篇文章給大家介紹了vue bus全局事件中心簡(jiǎn)單Demo,需要的朋友參考下吧
    2018-02-02
  • Vue 事件處理操作實(shí)例詳解

    Vue 事件處理操作實(shí)例詳解

    這篇文章主要介紹了Vue 事件處理操作,結(jié)合實(shí)例形式較為詳細(xì)的分析了vue.js事件處理相關(guān)的事件監(jiān)聽(tīng)、處理、修飾符等相關(guān)概念、用法及操作注意事項(xiàng),需要的朋友可以參考下
    2019-03-03
  • vue使用keep-alive實(shí)現(xiàn)數(shù)據(jù)緩存不刷新

    vue使用keep-alive實(shí)現(xiàn)數(shù)據(jù)緩存不刷新

    這篇文章主要介紹了vue使用keep-alive實(shí)現(xiàn)數(shù)據(jù)緩存不刷新,這里整理了詳細(xì)的代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • vue 自定義組件的寫(xiě)法與用法詳解

    vue 自定義組件的寫(xiě)法與用法詳解

    這篇文章主要介紹了vue 自定義組件的寫(xiě)法與用法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
    2020-03-03
  • Vue實(shí)現(xiàn)導(dǎo)出Excel表格文件提示“文件已損壞無(wú)法打開(kāi)”的解決方法

    Vue實(shí)現(xiàn)導(dǎo)出Excel表格文件提示“文件已損壞無(wú)法打開(kāi)”的解決方法

    xlsx用于讀取解析和寫(xiě)入Excel文件的JavaScript庫(kù),它提供了一系列的API處理Excel文件,使用該庫(kù),可以將數(shù)據(jù)轉(zhuǎn)換Excel文件并下載到本地,適用于在前端直接生成Excel文件,這篇文章主要介紹了Vue實(shí)現(xiàn)導(dǎo)出Excel表格,提示文件已損壞,無(wú)法打開(kāi)的解決方法,需要的朋友可以參考下
    2024-01-01

最新評(píng)論

顺平县| 庆元县| 东乡族自治县| 德保县| 道真| 松桃| 繁昌县| 南阳市| 潢川县| 沁源县| 安吉县| 汪清县| 土默特左旗| 尚志市| 南投县| 江门市| 六安市| 太原市| 灌阳县| 石首市| 华安县| 崇信县| 贵德县| 通许县| 龙江县| 嘉鱼县| 平昌县| 松桃| 永吉县| 商河县| 甘洛县| 榆树市| 肃宁县| 大理市| 卢龙县| 温州市| 新津县| 临高县| 香河县| 神池县| 积石山|