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

新手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文件進(jìn)行組件化的開發(fā)

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

二、搭建項目

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

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

輸入命令進(jìn)入項目: 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進(jìn)行導(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

詳細(xì)操作:

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

npm install

npm run dev

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

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

相關(guān)文章

  • vue中動態(tài)路由加載組件,找不到module問題及解決

    vue中動態(tài)路由加載組件,找不到module問題及解決

    這篇文章主要介紹了vue中動態(tài)路由加載組件,找不到module問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • 使用Vue寫一個todoList事件備忘錄經(jīng)典小案例

    使用Vue寫一個todoList事件備忘錄經(jīng)典小案例

    學(xué)習(xí)了幾天Vue之后終于迎來了第一個小案例,todoList是非常常見地一個小案例,下面這篇文章主要給大家介紹了關(guān)于使用Vue寫一個todoList事件備忘錄經(jīng)典小案例的相關(guān)資料,需要的朋友可以參考下
    2022-10-10
  • Vue 自定義指令實現(xiàn)一鍵 Copy功能

    Vue 自定義指令實現(xiàn)一鍵 Copy功能

    指令 (Directives) 是帶有 v- 前綴的特殊特性。這篇文章主要介紹了Vue 自定義指令實現(xiàn)一鍵 Copy的功能,需要的朋友可以參考下
    2019-09-09
  • 一文輕松理解Vuex

    一文輕松理解Vuex

    這篇文章主要介紹了Vuex及其使用方法,感興趣的同學(xué),可以參考下
    2021-04-04
  • Vue使用三方工具vueUse實現(xiàn)虛擬列表

    Vue使用三方工具vueUse實現(xiàn)虛擬列表

    其實采用vueUse中的useVirtualList方法同樣可以實現(xiàn)虛擬列表,這篇文章小編就來和大家詳細(xì)介紹一下如何使用vueUse實現(xiàn)簡單的虛擬列表效果吧
    2024-04-04
  • 如何手寫一個簡易的 Vuex

    如何手寫一個簡易的 Vuex

    這篇文章主要介紹了如何手寫一個簡易的 Vuex,幫助大家更好的理解和學(xué)習(xí)vue,感興趣的朋友可以了解下
    2020-10-10
  • Vue項目如何安裝引入使用Vant

    Vue項目如何安裝引入使用Vant

    Vant是一個專為移動端設(shè)計的輕量級組件庫,自2017年開源以來,提供了Vue2、Vue3及多平臺版本支持,安裝Vant時需要注意版本兼容問題,Vue3項目應(yīng)安裝最新版Vant3,而Vue2項目則需安裝Vant2,安裝錯誤時,需卸載后重新安裝正確版本
    2024-10-10
  • 在VUE3中禁止網(wǎng)頁返回到上一頁的方法

    在VUE3中禁止網(wǎng)頁返回到上一頁的方法

    這篇文章主要介紹了在VUE3中如何禁止網(wǎng)頁返回到上一頁,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-09-09
  • vue使用JSON編輯器:vue-json-editor詳解

    vue使用JSON編輯器:vue-json-editor詳解

    文章介紹了如何在Vue項目中使用JSON編輯器插件`vue-json-editor`,包括安裝、引入、注冊和使用示例,通過這些步驟,用戶可以在Vue應(yīng)用中輕松實現(xiàn)JSON數(shù)據(jù)的編輯功能,文章最后呼吁大家支持腳本之家
    2025-01-01
  • Vue數(shù)據(jù)驅(qū)動試圖的實現(xiàn)方法及原理

    Vue數(shù)據(jù)驅(qū)動試圖的實現(xiàn)方法及原理

    當(dāng)Vue實例中的數(shù)據(jù)(data)發(fā)生變化時,與之相關(guān)聯(lián)的視圖(template)會自動更新,反映出最新的數(shù)據(jù)狀態(tài), Vue的數(shù)據(jù)驅(qū)動視圖是通過其響應(yīng)式系統(tǒng)實現(xiàn)的,以下是Vue數(shù)據(jù)驅(qū)動視圖實現(xiàn)的核心原理,需要的朋友可以參考下
    2024-10-10

最新評論

玉树县| 丘北县| 广河县| 金门县| 昆山市| 凤山市| 新民市| 惠来县| 启东市| 关岭| 乃东县| 清水县| 尼勒克县| 贡嘎县| 田阳县| 卫辉市| 宝坻区| 德江县| 景洪市| 洛隆县| 舒兰市| 钟山县| 青神县| 利津县| 鄂尔多斯市| 民丰县| 班戈县| 门源| 七台河市| 中阳县| 桦南县| 怀宁县| 利辛县| 南皮县| 启东市| 宁城县| 虹口区| 新营市| 光山县| 仁化县| 禄丰县|