찾다
웹 프론트엔드JS 튜토리얼Vue+Vux 프로젝트(자세한 튜토리얼)
Vue+Vux 프로젝트(자세한 튜토리얼)Jun 23, 2018 pm 03:04 PM
vue프로젝트

이 기사에서는 Vue+Vux 프로젝트의 실용적인 아이디어를 소개하는 자세한 코드를 공유합니다. 도움이 필요한 친구들이 참고할 수 있습니다.

완벽한 라우팅, 서비스 제공""""`

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

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>
  <p id="app-box"></p>
  <!-- built files will be auto injected -->
 </body>
</html>

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

'에서 가져오기 페이지 main.js

import Vue from &#39;vue&#39;
import Vuex from &#39;vuex&#39;
import VueRouter from &#39;vue-router&#39;
import FastClick from &#39;fastclick&#39;
import {WechatPlugin, AjaxPlugin, LoadingPlugin, ToastPlugin, AlertPlugin} from &#39;vux&#39;
import App from &#39;./app.vue&#39;
/**
 * 加载插件
 */
Vue.use(Vuex)
Vue.use(VueRouter)
Vue.use(WechatPlugin)
Vue.use(AjaxPlugin)
Vue.use(LoadingPlugin)
Vue.use(ToastPlugin)
Vue.use(AlertPlugin)
/**
 * 定义常量
 */
const domainName = &#39;localhost:8010&#39;
const serverName = &#39;localhost:3000&#39;
const apiPrefix = serverName + &#39;/api/outer&#39;
const loginTimeOutErrorCode = &#39;login_timeout_error&#39;
/**
 * 设置vuex
 */
const store = new Vuex.Store({})
store.registerModule(&#39;vux&#39;, {
 state: {
  loading: false,
  showBack: true,
  title: &#39;&#39;
 },
 mutations: {
  updateLoading (state, loading) {
   state.loading = loading
  },
  updateShowBack (state, showBack) {
   state.showBack = showBack
  },
  updateTitle (state, title) {
   state.title = title
  }
 }
})
/**
 * 设置路由
 */
const routes = [
 // 初始页
 {
  path: &#39;/&#39;,
  component: function (resolve) {
   require([&#39;./components/init.vue&#39;], resolve)
  }
 },
 // 主页
 {
  path: &#39;/index&#39;,
  component: function (resolve) {
   require([&#39;./components/index.vue&#39;], resolve)
  },
  children: [
   // 测试页
   {
    path: &#39;test&#39;,
    component: function (resolve) {
     require([&#39;./components/tests/page.vue&#39;], resolve)
    }
   }
  ]
 },
 // 绑定页
 {
  path: &#39;/bind&#39;,
  component: function (resolve) {
   require([&#39;./components/bind.vue&#39;], resolve)
  }
 }
]
const router = new VueRouter({
 routes
})
router.beforeEach(function (to, from, next) {
 store.commit(&#39;updateLoading&#39;, true)
 store.commit(&#39;updateShowBack&#39;, true)
 next()
})
router.afterEach(function (to) {
 store.commit(&#39;updateLoading&#39;, false)
})
/**
 * 点击延迟
 */
FastClick.attach(document.body)
/**
 * 日志输出开关
 */
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: &#39;Loading&#39;
 })
 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 = &#39;请求失败&#39;
   if (response && response.data) {
    if (response.data.code === loginTimeOutErrorCode) {
     window.location.href = &#39;/&#39;
    }
    errorMessage = response.data.message
   }
   vue.$vux.alert.show({
    title: &#39;提示&#39;,
    content: errorMessage
   })
  } else {
   opts.error(error.response.data.data)
  }
 })
}
Vue.prototype.get = function (opts) {
 opts.method = &#39;get&#39;
 this.http(opts)
}
Vue.prototype.post = function (opts) {
 opts.method = &#39;post&#39;
 this.http(opts)
}
Vue.prototype.put = function (opts) {
 opts.method = &#39;put&#39;
 this.http(opts)
}
Vue.prototype.delete = function (opts) {
 opts.method = &#39;delete&#39;
 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: &#39;请检查输入&#39;
  })
 }
}
Vue.prototype.closeShowBack = function () {
 this.$store.commit(&#39;updateShowBack&#39;, false)
}
Vue.prototype.updateTitle = function (value) {
 this.$store.commit(&#39;updateTitle&#39;, value)
}
/**
 * 创建实例
 */
new Vue({
 store,
 router,
 render: h => h(App)
}).$mount(&#39;#app-box&#39;)
app.vue
<template>
 <p id="app">
  <loading v-model="isLoading"></loading>
  <transition>
   <router-view></router-view>
  </transition>
 </p>
</template>
<script>
 import {Loading} from &#39;vux&#39;
 import {mapState} from &#39;vuex&#39;
 export default {
  name: &#39;app&#39;,
  components: {
   Loading
  },
  computed: {
   ...mapState({
    isLoading: state => state.vux.isLoading
   })
  }
 }
</script>
<style lang="less">
 @import &#39;~vux/src/styles/reset.less&#39;;
 body {
  background-color: #fbf9fe;
 }
</style>
components/index.vue
<template>
 <p style="height:100%;">
  <top style="margin-bottom:46px"></top>
  <transition>
   <router-view></router-view>
  </transition>
  <bottom></bottom>
 </p>
</template>
<script>
 import Top from &#39;./layouts/top.vue&#39;
 import Bottom from &#39;./layouts/bottom.vue&#39;
 export default {
  components: {
   Top,
   Bottom
  }
 }
</script>
<style>
 html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
 }
</style>
components/tests/page.vue
<template>
 <p>
  <page @loadMore="loadMore" @refresh="refresh">
   <p>
    <p v-for="i in n">placeholder {{i}}</p>
   </p>
  </page>
 </p>
</template>
<script>
 import Page from &#39;../kits/page.vue&#39;
 import {cookie} from &#39;vux&#39;
 export default {
  components: {
   Page
  },
  created () {
   let vue = this
   vue.closeShowBack()
   vue.updateTitle(&#39;测试页面&#39;),
   //获取常量
    console.log(0)
   vue.get({
    url: &#39;/test/constants&#39;,
    headers: {
     &#39;token&#39;: cookie.get(&#39;token&#39;)
    },
    success: function (data) {
     cookie.set(&#39;constants&#39;,JSON.stringify(data),{
      expires: 1
     })
    }
   })
  },
  data () {
   return {
    n: 10,
   }
  },
  methods: {
   loadMore () {
    this.n += 10
   },
   refresh () {
    this.n = 10
   },
  }
 }
</script>

comComponents/tests/page.vue 코드의 ../kits/page.vue'는 제가 직접 작성하고 풀다운 새로고침에 추가한 구성요소입니다.

이 기록 요약은 방금 완료된 프로젝트에서 추출한 코드의 일부입니다. (참고: 이 프로젝트의 실제 코드는 runnable, runnable, runnable, runnable입니다.)

위 내용은 제가 컴파일한 것입니다 모두를 위해, 앞으로 모든 사람에게 도움이 되기를 바랍니다.

관련 기사:

WeChat 미니 프로그램 기능 요약(자세한 튜토리얼)

javaScript에서 휴대폰 번호 확인 도구인 PhoneUtils를 사용하는 방법

WeChat 미니 프로그램에서 다운로드 진행을 달성하는 방법 기사

WeChat 미니 프로그램에서 비디오 구성 요소를 사용하여 비디오를 재생하는 방법

위 내용은 Vue+Vux 프로젝트(자세한 튜토리얼)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
Vue常见面试题汇总(附答案解析)Vue常见面试题汇总(附答案解析)Apr 08, 2021 pm 07:54 PM

本篇文章给大家分享一些Vue面试题(附答案解析)。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

5 款适合国内使用的 Vue 移动端 UI 组件库5 款适合国内使用的 Vue 移动端 UI 组件库May 05, 2022 pm 09:11 PM

本篇文章给大家分享5 款适合国内使用的 Vue 移动端 UI 组件库,希望对大家有所帮助!

vue中props可以传递函数吗vue中props可以传递函数吗Jun 16, 2022 am 10:39 AM

vue中props可以传递函数;vue中可以将字符串、数组、数字和对象作为props传递,props主要用于组件的传值,目的为了接收外面传过来的数据,语法为“export default {methods: {myFunction() {// ...}}};”。

手把手带你利用vue3.x绘制流程图手把手带你利用vue3.x绘制流程图Jun 08, 2022 am 11:57 AM

利用vue3.x怎么绘制流程图?下面本篇文章给大家分享基于 vue3.x 的流程图绘制方法,希望对大家有所帮助!

如何覆盖组件库样式?React和Vue项目的解决方法浅析如何覆盖组件库样式?React和Vue项目的解决方法浅析May 16, 2022 am 11:15 AM

如何覆盖组件库样式?下面本篇文章给大家介绍一下React和Vue项目中优雅地覆盖组件库样式的方法,希望对大家有所帮助!

聊聊vue指令中的修饰符,常用事件修饰符总结聊聊vue指令中的修饰符,常用事件修饰符总结May 09, 2022 am 11:07 AM

本篇文章带大家聊聊vue指令中的修饰符,对比一下vue中的指令修饰符和dom事件中的event对象,介绍一下常用的事件修饰符,希望对大家有所帮助!

通过9个Vue3 组件库,看看聊前端的流行趋势!通过9个Vue3 组件库,看看聊前端的流行趋势!May 07, 2022 am 11:31 AM

本篇文章给大家分享9个开源的 Vue3 组件库,通过它们聊聊发现的前端的流行趋势,希望对大家有所帮助!

react与vue的虚拟dom有什么区别react与vue的虚拟dom有什么区别Apr 22, 2022 am 11:11 AM

react与vue的虚拟dom没有区别;react和vue的虚拟dom都是用js对象来模拟真实DOM,用虚拟DOM的diff来最小化更新真实DOM,可以减小不必要的性能损耗,按颗粒度分为不同的类型比较同层级dom节点,进行增、删、移的操作。

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

DVWA

DVWA

DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

Atom Editor Mac 버전 다운로드

Atom Editor Mac 버전 다운로드

가장 인기 있는 오픈 소스 편집기

Dreamweaver Mac版

Dreamweaver Mac版

시각적 웹 개발 도구

PhpStorm 맥 버전

PhpStorm 맥 버전

최신(2018.2.1) 전문 PHP 통합 개발 도구

SecList

SecList

SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.