vue Blog 學(xué)習(xí)筆記 (1) 安裝、頁面顯示

PJ Blog

// 項(xiàng)目根目錄下執(zhí)行
npm run watch

> @ watch D:\wamp\www\blog

> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
app
resources
  assets
    - js
  lang
  views
  • webpack.min.js
    解析模塊時(shí)應(yīng)該搜索的目錄
解析模塊好復(fù)雜啊,到處都有
mix.webpackConfig({
    resolve: {
        alias: {
            'components': 'assets/js/components',
            'config': 'assets/js/config',
            'lang': 'assets/js/lang',
            'plugins': 'assets/js/plugins',
            'vendor': 'assets/js/vendor',
            'views': 'assets/js/views',
            'dashboard': 'assets/js/views/dashboard',
        },
        modules: [
          'node_modules',
          path.resolve(__dirname, "resources")
        ]
    },
})

resolve.alias
創(chuàng)建 import 或 require 的別名,來確保模塊引入變得更簡單。例如,一些位于 src/ 文件夾下的常用模塊:

resolve.alias

resolve.modules
告訴 webpack 解析模塊時(shí)應(yīng)該搜索的目錄。
絕對(duì)路徑和相對(duì)路徑都能使用,但是要知道它們之間有一點(diǎn)差異。通過查看當(dāng)前目錄以及祖先路徑(即 ./node_modules, ../node_modules 等等),相對(duì)路徑將類似于 Node 查找 'node_modules' 的方式進(jìn)行查找。

使用絕對(duì)路徑,將只在給定目錄中搜索。

resolve.modules defaults to:
modules: ["node_modules"]

如果你想要添加一個(gè)目錄到模塊搜索目錄,此目錄優(yōu)先于 node_modules/ 搜索:

modules: [path.resolve(__dirname, "src"), "node_modules"]
  • 多語言 vue-i18n
/resources/assets/js/views/dashboard/System.vue
$t 怎么實(shí)現(xiàn)的哩
{{ $t(pages.systems) }}

/resources/assets/js/app.js
  import locales from 'lang'
  import VueI18n from 'vue-i18n';
  Vue.config.lang = Window.language
  const i18n = new VueI18n({
    locale: Vue.config.lang,
    messages: locales
  })
  • 為什么要用兩套路由系統(tǒng)
    // vue 路由
    resources/assets/js/routers.js

    // php 交互路由
    routes/api.php

    routers.js是vue的路由,是前端界面;
    api.php是后端路由

  • dashboard 后臺(tái)首頁
http://blog.app/dashboard/home

路由
resources/assets/js/routes.js
  export defaults [
    path: '/dashboard',
    component: Dashboard,
    beforeEnter: requireAuth,
    children: [
      {
        path: '/',
        redirect: '/dashboard/home'
      },
      {
        path: '/home',
        component: require('dashboard/Home.vue')
        // 此處的 dashboard 即為之前配置的解析別名模塊
        // 'dashboard': 'assets/js/views/dashboard',
      }
      ......
    ]
  ]

resources/assets/js/views/dashboard/Home.vue
export default {
    components: {
        Chart
    },
    data () {
        return {
            statistics: {}
        }
    },
    mounted() {
        this.$http.get('statistics')
            .then((response) => {
                this.statistics = response
            })
    }
}
路由 statistics 在 api.php 路由文件中定義
請求響應(yīng)包含以下內(nèi)容
{
  // `data` 由服務(wù)器提供的響應(yīng)
  data: {},

  // `status` 來自服務(wù)器響應(yīng)的 HTTP 狀態(tài)碼
  status: 200,

  // `statusText` 來自服務(wù)器響應(yīng)的 HTTP 狀態(tài)信息
  statusText: 'OK',

  // `headers` 服務(wù)器響應(yīng)的頭
  headers: {},

  // `config` 是為請求提供的配置信息
  config: {}
}

this.$http.get
vue 不再推薦使用 vue-resource, 推薦使用 axios

resources/assets/js/plugins/http/index.js
該文件實(shí)現(xiàn) Vue 中 this.$http.get() 使用 axios 庫
  • vue-table
/resources/assets/js/components/particals/Table.vue
<vue-table></vue-table>

resources/assets/js/app.js
Vue.component(
    'vue-table',
    require('components/dashboard/Table.vue')
);

resources/assets/js/components/dashboard/Table.vue

  • vue-router 路由插件
組件 vue-router
<div id="app">
  <h1>Hello App!</h1>
  <p>
    <!-- use router-link component for navigation. -->
    <!-- specify the link by passing the `to` prop. -->
    <!-- `<router-link>` will be rendered as an `<a>` tag by default -->
    <router-link to="/foo">Go to Foo</router-link>
    <router-link to="/bar">Go to Bar</router-link>
  </p>
  <!-- route outlet -->
  <!-- component matched by the route will render here -->
  <router-view></router-view>
</div>

<router-link> automatically gets the .router-link-active class 
when its target route is matched

<router-view></router-view>
Nested Routes
<div id="app">
  <router-view></router-view>
</div>
const User = {
  template: '<div>User {{ $route.params.id }}</div>'
}
const router = new VueRouter({
  routes: [
    { path: '/user/:id', component: User }
  ]
})


The <router-view> here is a top-level outlet. 
It renders the component matched by a top level route. 
Similarly, a rendered component can also contain its own, nested <router-view>. 
For example, if we add one inside the User component's template:

const User = {
  template: `
    <div class="user">
      <h2>User {{ $route.params.id }}</h2>
      <router-view></router-view>
    </div>
  `
}

后臺(tái)的控制器放在 Api 目錄,思想就是當(dāng)做接口的形式給 Vue 返回?cái)?shù)據(jù)呀
Fractal provides a presentation and transformation layer for complex data output, the like found in RESTful APIs,
and works really well with JSON. Think of this as a view layer for your JSON/YAML/etc.

  • User.vue 用戶列表首頁
    還不知道怎讀請求的數(shù)據(jù)過來呀!

包含 Table.vue 文件
loadData() {
// User.vue 文件中 <vue-table></vue-table> 節(jié)點(diǎn)有屬性 api-url="user"
var url = this.apiUrl // 從哪里取的值

}

resources/assets/js/views/dashboard/user/User.vue

<template>
    <div class="row">
        <vue-table :title="$t('page.users')" :fields="fields" api-url="user" 
            @table-action="tableActions" show-paginate>
            <div slot="buttons">
                <router-link to="/dashboard/users/create" class="btn btn-success">
                  {{ $t('page.create') }}
                </router-link>
            </div>
        </vue-table>
    </div>
</template>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,732評(píng)論 6 539
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 99,214評(píng)論 3 426
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 177,781評(píng)論 0 382
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,588評(píng)論 1 316
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 72,315評(píng)論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 55,699評(píng)論 1 327
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,698評(píng)論 3 446
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,882評(píng)論 0 289
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 49,441評(píng)論 1 335
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 41,189評(píng)論 3 356
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 43,388評(píng)論 1 372
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,933評(píng)論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 44,613評(píng)論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,023評(píng)論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,310評(píng)論 1 293
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 52,112評(píng)論 3 398
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 48,334評(píng)論 2 377

推薦閱讀更多精彩內(nèi)容

  • 概要 64學(xué)時(shí) 3.5學(xué)分 章節(jié)安排 電子商務(wù)網(wǎng)站概況 HTML5+CSS3 JavaScript Node 電子...
    阿啊阿吖丁閱讀 9,266評(píng)論 0 3
  • 個(gè)人基于對(duì) Vuejs 的學(xué)習(xí)制作了一個(gè) Todo 單頁應(yīng)用 Lightodo,功能包括:添加待辦事項(xiàng)卡片,對(duì)卡片...
    AlessiaLi閱讀 21,590評(píng)論 16 308
  • 基于Vue的一些資料 內(nèi)容 UI組件 開發(fā)框架 實(shí)用庫 服務(wù)端 輔助工具 應(yīng)用實(shí)例 Demo示例 element★...
    嘗了又嘗閱讀 1,166評(píng)論 0 1
  • 個(gè)人入門學(xué)習(xí)用筆記、不過多作為參考依據(jù)。如有錯(cuò)誤歡迎斧正 目錄 簡書好像不支持錨點(diǎn)、復(fù)制搜索(反正也是寫給我自己看...
    kirito_song閱讀 2,487評(píng)論 1 37
  • Address:https://www.zybuluo.com/XiangZhou/note/208532 Exp...
    天蠍蒗漫閱讀 11,354評(píng)論 2 55