All Projects → codica2 → vue-app-best-practice

codica2 / vue-app-best-practice

Licence: other
Vue application sample with all the best practices

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to vue-app-best-practice

vue-cli-plugin-bootstrap-vue
vue-cli 3 plugin to add bootstrap-vue
Stars: ✭ 35 (+25%)
Mutual labels:  vue-cli-3
vue-element-admin-ts
vue-element-admin 的 typescript 版本
Stars: ✭ 101 (+260.71%)
Mutual labels:  vue-cli-3
cloud-music-mobile
This is a music player
Stars: ✭ 22 (-21.43%)
Mutual labels:  vue-cli-3
concats
🔨 Desktop app to output a single-column csv file of rows of concatenated fields from an input csv or tsv file.
Stars: ✭ 20 (-28.57%)
Mutual labels:  vue-cli-3
vue-admin
无 UI 框架依赖(默认 vue 3.x 版本)
Stars: ✭ 99 (+253.57%)
Mutual labels:  vue-cli-3
vue-large-scale-folder-structure
Vue Js, 2 vue-cli large scale folder structure with vuex, vue-router, axios
Stars: ✭ 29 (+3.57%)
Mutual labels:  vue-cli-3
vuetify-with-storybook
Setting up Storybook with Vuetify the right way
Stars: ✭ 116 (+314.29%)
Mutual labels:  vue-cli-3
ECHI VUE CLI3.0
[email protected] + axios + mock + typescript + element-ui + scss + webpack4构建的企业级应用项目基础模板;
Stars: ✭ 15 (-46.43%)
Mutual labels:  vue-cli-3
Vi-Ui
💙 A simple but consistent user interface made for Vue
Stars: ✭ 42 (+50%)
Mutual labels:  vue-cli-3
vue-cli-3.x-doc-cn
vue-cli 3.x 中文文档
Stars: ✭ 49 (+75%)
Mutual labels:  vue-cli-3
olivia-ai.org
💻 The website and an online client for Olivia
Stars: ✭ 26 (-7.14%)
Mutual labels:  vue-cli-3
new-ara-web
KAIST Community Ara Renewal Project
Stars: ✭ 19 (-32.14%)
Mutual labels:  vue-cli-3
vue-cli3-example
🍭 A Mand Mobile project example for @vue/cli 3.0
Stars: ✭ 25 (-10.71%)
Mutual labels:  vue-cli-3
Spring Boot Vuejs
Example project showing how to build a Spring Boot App providing a GUI with Vue.js
Stars: ✭ 1,818 (+6392.86%)
Mutual labels:  vue-cli-3

Vue base template

Description

Vue application created with Vue-cli, Vuex for state management and Vue-router for routing.

Project installation

Clone project
git clone [link]

Install dependencies

yarn

Start server

yarn serve

For production build

yarn build

If you want to customize the project - run vue ui and select the current project.

For this command, you need vue-cli 3. In case you don’t have this package installed, run the following command or find out the step-by-step tutorial using official documentation.

Remove vue-cli 2

yarn global remove vue-cli

Install vue-cli 3 with a global flag

yarn global add @vue/cli

Check version

vue --version

File structure

├public/            => Any static assets are placed here.
├src/
| ├─api/            => API functions
| ├─assets/         => Folder for relative path files’ import
| ├─components/     => Global components
| ├─directives/     => Custom directives
| ├─icons/          => SVG icons
| ├─mixins/         => Global mixins
| ├─router/         => Vue-router
| ├─store/          => Vuex
| ├─styles/         => Global styles
| ├─utils/          => Global constants and helper functions
| ├─views/          => Layouts for view
| ├─App.vue         => Main component
| └─main.js         => Main JS file
└static/            => Folder for static path files import

Vuex structure

Vuex store is divided into modules. Each module has a main file index.js where Vuex patterns are gathered in actions, mutations and getters.

store/
├─modules/
|  └─bar/
|     ├─actions.js
|     ├─mutations.js
|     ├─getters.js
|     └─index.js
├──app.js
├─getters.js
├─mutations-types.js
└─index.js

Modules are installed in the index.js file, which is in the Store root folder. The getters.js file is global to get application states. File with name mutations-types.js has names of mutations constants.

/* ... */
import app from './modules/app'
import bar from './modules/bar'
import getters from './getters'
/* ... */

Vue.use(Vuex)

const store = new Vuex.Store({
  modules: {
    app,
    bar
  },
  getters
})

export default store

About Actions

To handle asynchronous actions we usually use Promise

import API from '@/api/index'

export const actions = {
  AsyncAction: ({ dispatch, commit }, payload) => {
    API.fetch(payload.method, payload.path, payload.data)
      .then(response => {
        commit('MUTATION_TYPE', response)
      })
      .catch(error => {
        dispatch('FailResponse', error)
      })
  },
  Action: ({ commit }, payload) => {
  	commit('MUTATION_TYPE', payload)
  }
}

About directives

A directive is a special token in the markup that tells the library to take some actions to a DOM element. All custom directives are in different folders and are imported only if they are used in the component.

import directive from './directive'

const install = (Vue) => {
  Vue.directive('directive', directive)
}

if (window.Vue) {
  window['directive'] = directive
  Vue.use(install)
}

directive.install = install
export default directive

Component SvgIcon

Component icons are resolved as global for using in different components. Afterwards, all the SVG icons become Vue components.

// SvgIcon.vue
<template lang="pug">
  component(:is="iconClass" :class="svgClass")
</template>

<script>
import Vue from 'vue'

export default {
  name: 'SvgIcon',
  props: {
    iconClass: {
      type: String,
      required: true
    },
    className: {
      type: String,
      default: ''
    }
  },
  computed: {
    svgClass() {
      if (this.className) {
        return 'svg-icon ' + this.className
      } else {
        return 'svg-icon'
      }
    }
  },
  created() {
    Vue.component(this.iconClass, () => import(`@/icons/svg/${this.iconClass}.svg`))
  }
}
</script>
import Vue from 'vue'
import SvgIcon from '@/components/SvgIcon'

// register globally
Vue.component('svg-icon', SvgIcon)

// main.js

import './icons'

About request

For all the requests we are using axios. Create an axios instance for using base request template.

import axios from 'axios'

const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  headers: {
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
    'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token'
  },
  timeout: 5000
})
service.interceptors.request.use(
  config => {
    return config
  },
  error => {
    console.log(error)
    Promise.reject(error)
  }
)
service.interceptors.response.use(
  response => response,
  error => {
    console.log('err' + error)
    // Message({
    //  message: error.message,
    //  type: 'error',
    //  duration: 5000
    // })
    return Promise.reject(error)
  }
)

export default service

License

vue-base-template is Copyright © 2015-2018 Codica. It is released under the MIT License.

About Codica

Codica logo

We love open source software! See our other projects or hire us to design, develop, and grow your product.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].