<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

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

        來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:24:33
        文檔

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

        Vue+Vux項(xiàng)目實(shí)踐完整代碼:提供完整的路由,services````````````` ------------------------------------------------------------------------------------------------------------------------------------------------
        推薦度:
        導(dǎo)讀Vue+Vux項(xiàng)目實(shí)踐完整代碼:提供完整的路由,services````````````` ------------------------------------------------------------------------------------------------------------------------------------------------

        提供完整的路由,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í)踐完整代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

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

        Vue+Vux項(xiàng)目實(shí)踐完整代碼:提供完整的路由,services````````````` ------------------------------------------------------------------------------------------------------------------------------------------------
        推薦度:
        標(biāo)簽: VUE 代碼 完整
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 18禁免费无码无遮挡不卡网站 | 亚洲国产精品综合久久网络| 亚洲av乱码一区二区三区香蕉| 在线观看肉片AV网站免费| 久久亚洲中文字幕精品一区| 日韩免费码中文在线观看| 亚洲国产精品成人| www成人免费视频| 亚洲av无码国产精品色午夜字幕| 中文字幕在线视频免费观看| 亚洲自偷自偷图片| 少妇人妻偷人精品免费视频| 亚洲特级aaaaaa毛片| 国产va精品免费观看| 亚洲国产精品久久久久秋霞小| 国产美女精品视频免费观看| 日本视频免费观看| 亚洲成AV人片在线观看| 免费无码一区二区三区| 国产日本亚洲一区二区三区| 日韩免费一级毛片| 久久久久久久久久久免费精品| 久久久久亚洲av无码专区蜜芽| 91九色老熟女免费资源站| 国产 亚洲 中文在线 字幕| 国产色婷婷精品免费视频| eeuss免费影院| 久久亚洲国产成人精品性色| 久久久久国色AV免费看图片| 免费精品国产自产拍在线观看| 亚洲精品无码专区在线在线播放 | 亚洲精品乱码久久久久久V| 亚洲午夜日韩高清一区| 日本卡1卡2卡三卡免费| 亚洲三级中文字幕| 亚洲精品国产V片在线观看 | 亚洲国产成人精品无码区花野真一| 亚洲成a人片在线观看久| 久久久精品免费国产四虎| 亚洲中文字幕久久精品无码A| 自拍偷自拍亚洲精品第1页|