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

Vue+Vux項(xiàng)目實(shí)踐完整代碼

 更新時(shí)間:2017年11月30日 11:41:33   作者:采香菇的小火柴  
本文給大家分享一段詳細(xì)的代碼給大家介紹Vue+Vux項(xiàng)目實(shí)踐思路,需要的朋友可以參考下

提供完整的路由,services`````````````

   ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

index.html

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
  <title>insurance-weixin</title>
 </head>
 <body>
  <div id="app-box"></div>
  <!-- built files will be auto injected -->
 </body>
</html>

   ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

main.js

import Vue from 'vue'
import Vuex from 'vuex'
import VueRouter from 'vue-router'
import FastClick from 'fastclick'
import {WechatPlugin, AjaxPlugin, LoadingPlugin, ToastPlugin, AlertPlugin} from 'vux'
import App from './app.vue'
/**
 * 加載插件
 */
Vue.use(Vuex)
Vue.use(VueRouter)
Vue.use(WechatPlugin)
Vue.use(AjaxPlugin)
Vue.use(LoadingPlugin)
Vue.use(ToastPlugin)
Vue.use(AlertPlugin)
/**
 * 定義常量
 */
const domainName = 'localhost:8010'
const serverName = 'localhost:3000'
const apiPrefix = serverName + '/api/outer'
const loginTimeOutErrorCode = 'login_timeout_error'
/**
 * 設(shè)置vuex
 */
const store = new Vuex.Store({})
store.registerModule('vux', {
 state: {
  loading: false,
  showBack: true,
  title: ''
 },
 mutations: {
  updateLoading (state, loading) {
   state.loading = loading
  },
  updateShowBack (state, showBack) {
   state.showBack = showBack
  },
  updateTitle (state, title) {
   state.title = title
  }
 }
})
/**
 * 設(shè)置路由
 */
const routes = [
 // 初始頁
 {
  path: '/',
  component: function (resolve) {
   require(['./components/init.vue'], resolve)
  }
 },
 // 主頁
 {
  path: '/index',
  component: function (resolve) {
   require(['./components/index.vue'], resolve)
  },
  children: [
   // 測試頁
   {
    path: 'test',
    component: function (resolve) {
     require(['./components/tests/page.vue'], resolve)
    }
   }
  ]
 },
 // 綁定頁
 {
  path: '/bind',
  component: function (resolve) {
   require(['./components/bind.vue'], resolve)
  }
 }
]
const router = new VueRouter({
 routes
})
router.beforeEach(function (to, from, next) {
 store.commit('updateLoading', true)
 store.commit('updateShowBack', true)
 next()
})
router.afterEach(function (to) {
 store.commit('updateLoading', false)
})
/**
 * 點(diǎn)擊延遲
 */
FastClick.attach(document.body)
/**
 * 日志輸出開關(guān)
 */
Vue.config.productionTip = true
/**
 * 定義全局公用常量
 */
Vue.prototype.domainName = domainName
Vue.prototype.serverName = serverName
Vue.prototype.apiPrefix = apiPrefix
/**
 * 定義全局公用方法
 */
Vue.prototype.http = function (opts) {
 let vue = this
 vue.$vux.loading.show({
  text: 'Loading'
 })
 vue.$http({
  method: opts.method,
  url: apiPrefix + opts.url,
  headers: opts.headers || {},
  params: opts.params || {},
  data: opts.data || {}
 }).then(function (response) {
  vue.$vux.loading.hide()
  opts.success(response.data.data)
 }).catch(function (error) {
  vue.$vux.loading.hide()
  if (!opts.error) {
   let response = error.response
   let errorMessage = '請求失敗'
   if (response && response.data) {
    if (response.data.code === loginTimeOutErrorCode) {
     window.location.href = '/'
    }
    errorMessage = response.data.message
   }
   vue.$vux.alert.show({
    title: '提示',
    content: errorMessage
   })
  } else {
   opts.error(error.response.data.data)
  }
 })
}
Vue.prototype.get = function (opts) {
 opts.method = 'get'
 this.http(opts)
}
Vue.prototype.post = function (opts) {
 opts.method = 'post'
 this.http(opts)
}
Vue.prototype.put = function (opts) {
 opts.method = 'put'
 this.http(opts)
}
Vue.prototype.delete = function (opts) {
 opts.method = 'delete'
 this.http(opts)
}
Vue.prototype.valid = function (opts) {
 let vue = this
 let valid = true
 if (opts.ref && !opts.ref.valid) {
  valid = false
 }
 if (opts.ignoreRefs) {
  let newRefs = []
  for (let i in opts.refs) {
   let ref = opts.refs[i]
   for (let j in opts.ignoreRefs) {
    let ignoreRef = opts.ignoreRefs[j]
    if (ref !== ignoreRef) {
     newRefs.push(ref)
    }
   }
  }
  opts.refs = newRefs
 }
 for (let i in opts.refs) {
  if (!opts.refs[i].valid) {
   valid = false
   break
  }
 }
 if (valid) {
  opts.success()
 } else if (opts.error) {
  opts.error()
 } else {
  vue.$vux.toast.show({
   text: '請檢查輸入'
  })
 }
}
Vue.prototype.closeShowBack = function () {
 this.$store.commit('updateShowBack', false)
}
Vue.prototype.updateTitle = function (value) {
 this.$store.commit('updateTitle', value)
}
/**
 * 創(chuàng)建實(shí)例
 */
new Vue({
 store,
 router,
 render: h => h(App)
}).$mount('#app-box')
app.vue
<template>
 <div id="app">
  <loading v-model="isLoading"></loading>
  <transition>
   <router-view></router-view>
  </transition>
 </div>
</template>
<script>
 import {Loading} from 'vux'
 import {mapState} from 'vuex'
 export default {
  name: 'app',
  components: {
   Loading
  },
  computed: {
   ...mapState({
    isLoading: state => state.vux.isLoading
   })
  }
 }
</script>
<style lang="less">
 @import '~vux/src/styles/reset.less';
 body {
  background-color: #fbf9fe;
 }
</style>
components/index.vue
<template>
 <div style="height:100%;">
  <top style="margin-bottom:46px"></top>
  <transition>
   <router-view></router-view>
  </transition>
  <bottom></bottom>
 </div>
</template>
<script>
 import Top from './layouts/top.vue'
 import Bottom from './layouts/bottom.vue'
 export default {
  components: {
   Top,
   Bottom
  }
 }
</script>
<style>
 html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
 }
</style>
components/tests/page.vue
<template>
 <div>
  <page @loadMore="loadMore" @refresh="refresh">
   <div>
    <p v-for="i in n">placeholder {{i}}</p>
   </div>
  </page>
 </div>
</template>
<script>
 import Page from '../kits/page.vue'
 import {cookie} from 'vux'
 export default {
  components: {
   Page
  },
  created () {
   let vue = this
   vue.closeShowBack()
   vue.updateTitle('測試頁面'),
   //獲取常量
    console.log(0)
   vue.get({
    url: '/test/constants',
    headers: {
     'token': cookie.get('token')
    },
    success: function (data) {
     cookie.set('constants',JSON.stringify(data),{
      expires: 1
     })
    }
   })
  },
  data () {
   return {
    n: 10,
   }
  },
  methods: {
   loadMore () {
    this.n += 10
   },
   refresh () {
    this.n = 10
   },
  }
 }
</script>

components/tests/page.vue代碼中的 import Page from '../kits/page.vue'是我自己寫的下拉刷新上啦加在的組件,運(yùn)行的話刪掉這些引用就可以了。

本次記錄摘要是從剛剛完成的項(xiàng)目中抽離的部分代碼(注:本項(xiàng)目實(shí)踐代碼,可運(yùn)行,可運(yùn)行,可運(yùn)行,可運(yùn)行)

總結(jié)

以上所述是小編給大家介紹的Vue+Vux項(xiàng)目實(shí)踐完整代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • vue中多個(gè)文件下載實(shí)現(xiàn)打包壓縮下載示例

    vue中多個(gè)文件下載實(shí)現(xiàn)打包壓縮下載示例

    這篇文章主要為大家介紹了vue中多個(gè)文件下載實(shí)現(xiàn)打包壓縮下載的發(fā)發(fā)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • 解決Vue路由導(dǎo)航報(bào)錯(cuò):NavigationDuplicated:?Avoided?redundant?navigation?to?current?location

    解決Vue路由導(dǎo)航報(bào)錯(cuò):NavigationDuplicated:?Avoided?redundant?navig

    這篇文章主要給大家介紹了關(guān)于解決Vue路由導(dǎo)航報(bào)錯(cuò):NavigationDuplicated:?Avoided?redundant?navigation?to?current?location的相關(guān)資料,這是最近做項(xiàng)目時(shí)候遇到的一個(gè)問題,現(xiàn)將解決辦法分享出來,需要的朋友可以參考下
    2023-01-01
  • vue 使用lodash實(shí)現(xiàn)對象數(shù)組深拷貝操作

    vue 使用lodash實(shí)現(xiàn)對象數(shù)組深拷貝操作

    這篇文章主要介紹了vue 使用lodash實(shí)現(xiàn)對象數(shù)組深拷貝操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • vue3中項(xiàng)目優(yōu)化方法詳解(Web?Worker的使用)

    vue3中項(xiàng)目優(yōu)化方法詳解(Web?Worker的使用)

    最近在做vue3的項(xiàng)目中,遇到了計(jì)算量龐大導(dǎo)致頁面響應(yīng)緩慢的問題,所以下面這篇文章主要給大家介紹了關(guān)于vue3中項(xiàng)目優(yōu)化方法的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-07-07
  • vue圖片加載失敗時(shí)用默認(rèn)圖片替換的方法

    vue圖片加載失敗時(shí)用默認(rèn)圖片替換的方法

    這篇文章主要給大家介紹了關(guān)于vue圖片加載失敗時(shí)用默認(rèn)圖片替換的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • Vue中使一個(gè)div鋪滿全屏的實(shí)現(xiàn)

    Vue中使一個(gè)div鋪滿全屏的實(shí)現(xiàn)

    最近在項(xiàng)目開發(fā)中,就遇到了這個(gè)問題,Vue中如何使一個(gè)div鋪滿全屏,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-07-07
  • 從vue源碼解析Vue.set()和this.$set()

    從vue源碼解析Vue.set()和this.$set()

    這篇文章主要介紹了從vue源碼看Vue.set()和this.$set()的相關(guān)知識,我們先來從Vue提供的Vue.set()和this.$set()這兩個(gè)api看看它內(nèi)部是怎么實(shí)現(xiàn)的。感興趣的朋友跟隨小編一起看看吧
    2018-08-08
  • vue-i18n的9以上版本中@被用作特殊字符處理,直接用會報(bào)錯(cuò)問題

    vue-i18n的9以上版本中@被用作特殊字符處理,直接用會報(bào)錯(cuò)問題

    這篇文章主要介紹了vue-i18n的9以上版本中@被用作特殊字符處理,直接用會報(bào)錯(cuò)問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • axios?發(fā)?post?請求,后端接收不到參數(shù)的完美解決方案

    axios?發(fā)?post?請求,后端接收不到參數(shù)的完美解決方案

    這篇文章主要介紹了axios?發(fā)?post?請求,后端接收不到參數(shù)的解決方案,場景很簡單,就是一個(gè)正常 axios post 請求,本文給大家分享問題原因分析及解決方案需要的朋友可以參考下
    2022-12-12
  • vue項(xiàng)目打包部署到服務(wù)器的方法示例

    vue項(xiàng)目打包部署到服務(wù)器的方法示例

    這篇文章主要介紹了vue項(xiàng)目打包部署到服務(wù)器的方法示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-08-08

最新評論

磐安县| 鄂托克旗| 云浮市| 老河口市| 上饶市| 夏河县| 伊川县| 儋州市| 威海市| 调兵山市| 商洛市| 甘南县| 应城市| 磐石市| 武冈市| 高尔夫| 马山县| 深水埗区| 五台县| 洛隆县| 南投市| 寿阳县| 来凤县| 睢宁县| 保定市| 崇州市| 沂南县| 修文县| 平和县| 洛川县| 开封县| 碌曲县| 榕江县| 玉环县| 城口县| 房产| 宣武区| 绩溪县| 繁峙县| 安义县| 洛宁县|