亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

新手vue構(gòu)建單頁面應(yīng)用實例代碼

 更新時間:2017年09月18日 09:29:27   作者:小任性415  
本篇文章主要介紹了新手vue構(gòu)建單頁面應(yīng)用實例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

本文介紹了新手vue構(gòu)建單頁面應(yīng)用實例代碼,分享給大家,具體如下

步驟:

1.使用vue-cli創(chuàng)建項目
2.使用vue-router實現(xiàn)單頁路由
3.用vuex管理我們的數(shù)據(jù)流
4.使用vue-resource請求我們的node服務(wù)端
5.使用.vue文件進行組件化的開發(fā)

一、目錄結(jié)構(gòu):

二、搭建項目

先安裝 vue-cli: sudo npm install -g vue-cli

使用vue-cli構(gòu)建初始化項目:vue init webpack project(創(chuàng)建webpack項目并下載依賴)

輸入命令進入項目: cd my-project 

安裝依賴: npm install

npm i

開始運行: npm run dev (或輸入http://localhost:8080),在熱加載中運行我們的應(yīng)用

它會去找到package.json的scripts對象,執(zhí)行node bulid/dev-server.js

在這文件里,配置了Webpack,會讓它去編譯項目文件,并且運行服務(wù)器。

這些都準(zhǔn)備好后,我們需要為我們的路由、XHR請求、數(shù)據(jù)管理下載三個庫,我們可以從vue的官網(wǎng)中找到他們。另外我們使用bootstrap作為我的UI庫:

 npm i vue-resource vue-router vuex bootstrap --save

三、項目開始

初始化項目(main.js)

查看我們的應(yīng)用文件,我們可以在src目錄下找到App.vue和main.js文件中,我們引入Vue和App,且創(chuàng)建了一個vue的實例(因為在router這行引入了App組件router.start(App,'#app'))

import Vue from 'vue'
import App from './App'
import router from './router'

import VueResource from 'vue-resource'
Vue.use(VueResource)
Vue.config.productionTip = false

new Vue({
 el: '#app',
 router,
 template: '<App/>',
 components: { App }
})

index.html

<body>
  <div id="app"></div>
 </body>

App.vue

<template>
 <div id="app">
  <div class="row">
   <div class="col-xs-offset-2 col-xs-8">
    <div class="page-header">
     <h2>Router Basic - 01</h2>
    </div>
   </div>
  </div>
  <div class="row">
    <div class="col-xs-2 col-xs-offset-2">
     <ul class="list-group">
      <!--使用指令v-link進行導(dǎo)航-->
      <a class="list-group-item"><router-link to="/home">Home</router-link></a>
      <a class="list-group-item"><router-link to="/about">About</router-link></a>
      <a class="list-group-item"><router-link to="/contact">Contact</router-link></a>
     </ul>
    </div>
    <div class="col-xs-6">
     <div class="panel">
      <div class="panel-body">
       <!--用于渲染匹配的組件-->
       <router-view></router-view>
      </div>
     </div>
    </div>
   </div>
  </div>
 </div>
</template>

<script>
export default {
 name: 'app'
}
</script>

src/components/Home.vue 作為我們的首頁

<template id="contact">
 <div>
  <h1>Home</h1>
  <p>This is the tutorial about Contact.</p>
 </div>
</template>

<script>
export default {
 '/hello': 'Hello'
}
</script>

src/components/About.vue

<template id="about">
  <div>
    <h1>About</h1>
    <p>This is the tutorial about vue-router.</p>
  </div>
</template>
<script>
export default {
 '/about': 'About'
}
</script>

src/components/Contact.vue

<template id="contact">
  <div>
    <h1>Contact</h1>
    <p>This is the tutorial about Contact.</p>
  </div>
</template>

export default {
 '/contact': 'contact'
}
</script>

src/index.js

import Vue from 'vue'
import Router from 'vue-router'
import Hello from '@/components/Hello'
import Home from '@/components/Home'
import About from '@/components/About'
import Contact from '@/components/Contact'
import 'bootstrap/dist/css/bootstrap.css'

Vue.use(Router)

export default new Router({
 routes: [
  {
   path: '/',
   name: 'Hello',
   component: Hello
  },
  {
   path: '/home',
   name: 'Home',
   component: Home
  },
  {
   path: '/about',
   name: 'About',
   component: About
  },
  {
   path: '/contact',
   name: '/Contact',
   component: Contact
  }
 ]
})

spa地址:https://github.com/cinderellastory415/vue-demo/tree/master/spa

詳細操作:

git clone https://github.com/cinderellastory415/vue-demo/tree/master/spa

npm install

npm run dev

輸入以上命令,即可查看效果。

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

相關(guān)文章

  • Vue開發(fā)之watch監(jiān)聽數(shù)組、對象、變量操作分析

    Vue開發(fā)之watch監(jiān)聽數(shù)組、對象、變量操作分析

    這篇文章主要介紹了Vue開發(fā)之watch監(jiān)聽數(shù)組、對象、變量操作,結(jié)合實例形式分析了vue.js使用Watch針對數(shù)組、對象、變量監(jiān)聽相關(guān)操作技巧,需要的朋友可以參考下
    2019-04-04
  • 解決vue-router進行build無法正常顯示路由頁面的問題

    解決vue-router進行build無法正常顯示路由頁面的問題

    下面小編就為大家分享一篇解決vue-router進行build無法正常顯示路由頁面的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • vue?請求攔截器的配置方法詳解

    vue?請求攔截器的配置方法詳解

    這篇文章主要為大家介紹了vue?請求攔截器的配置方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-01-01
  • Vue之插件詳解

    Vue之插件詳解

    這篇文章主要為大家介紹了Vue之插件,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助,希望能夠給你帶來幫助
    2021-11-11
  • Vue+ssh框架實現(xiàn)在線聊天

    Vue+ssh框架實現(xiàn)在線聊天

    這篇文章主要為大家詳細介紹了Vue+ssh框架實現(xiàn)在線聊天,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • Vue實現(xiàn)調(diào)用PC端攝像頭實時拍照

    Vue實現(xiàn)調(diào)用PC端攝像頭實時拍照

    這篇文章主要為大家詳細介紹了Vue實現(xiàn)調(diào)用PC端攝像頭實時拍照,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • vue中添加mp3音頻文件的方法

    vue中添加mp3音頻文件的方法

    本篇文章主要介紹了vue中添加mp3音頻文件的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • Vue.js教程之a(chǎn)xios與網(wǎng)絡(luò)傳輸?shù)膶W(xué)習(xí)實踐

    Vue.js教程之a(chǎn)xios與網(wǎng)絡(luò)傳輸?shù)膶W(xué)習(xí)實踐

    這篇文章主要給大家介紹了Vue.js之a(chǎn)xios與網(wǎng)絡(luò)傳輸?shù)南嚓P(guān)資料,文中介紹的非常詳細,對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面跟隨小編一起來學(xué)習(xí)學(xué)習(xí)吧。
    2017-04-04
  • vue3.2?Composition?API項目依賴升級

    vue3.2?Composition?API項目依賴升級

    這篇文章主要為大家介紹了vue3.2?Composition?API項目依賴升級示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • vue3+ts+vant移動端H5項目搭建的實現(xiàn)步驟

    vue3+ts+vant移動端H5項目搭建的實現(xiàn)步驟

    本文主要介紹了vue3+ts+vant移動端H5項目搭建,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06

最新評論