Code Monkey home page Code Monkey logo

vue-starter's Introduction

Technical Stack

Webpack + Babel + VueJS

Dev & Build & Test

npm run dev
npm run build
npm run test:unit

Async & Await Supported

function timeout(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function hello(name) {
  await timeout(3000);
  console.log(`Hello ${name},`);
}

hello('Khank'); // will print 'Hello Khank' after 3s

Router Supported

import HelloWorld from '../components/HelloWorld'
import SecondWorld from '../components/SecondWorld'

export default new Router({
    routes: [
        {
            path: '/',
            name: 'HelloWorld',
            component: HelloWorld
        },
        {
            path: '/secondworld',
            name: 'SecondWorld',
            component: SecondWorld
        },
    ]
})

ADM Supported

const SecondWorld = () => import(/* webpackChunkName: "secondworld" */ '../components/SecondWorld')

Event Bus Supported

Sender component

<template>
<div><button @click="emitHelloClickEvent()">Emit event</button></div>
</template>

<script>
  export default {
    methods: {
      emitHelloClickEvent() {
        this.$eventBus.$emit('hello', 'i hear you');
      }
    }
  }
</script>

Receiver component

<script>
export default {
  created() {
    // Listening the event hello
    this.$eventBus.$on('hello', this.handler);
  },
  methods: {
    handler(e) {
      console.log('RECEIVE EVENTS', e)
    }
  }
}
</script>

Vuex Supported

1/ Define Action Name at constants.js

export const INCREASE_COUNT = 'increase_count';

2/ Auto mapping constants to mutations in actions.js

3/ Define Mutation of Action at mutations.js

mutations[INCREASE_COUNT] = (state, num = 1) => {
    state.testCount += num;
}

4/ Usage Component

<template>

<div><button @click="handleClick()">Increase</button> {{count}}</div>
</template>

<script>
import { mapActions } from 'vuex'
import { INCREASE_COUNT } from '../store/constants'

export default {
  computed: {
    count () {
      return this.$store.state.testCount 
    }
  },
  methods: {
    // map actions to component
    ...mapActions([ INCREASE_COUNT ]),
    handleClick() {
      this[INCREASE_COUNT](2);
    }
  }
}
</script>

Deployment

Update Assets Path

1/ Update output.publicPath at file webpack.config.js if you want to change assets path.

2/ If you want to set asset path on runtime, just add global variables before loading file assetPath

<script>
window.assetUrl  = 'http://localhost/vue-starter/dist/';
</script>

References

browsers list config

vue-starter's People

Stargazers

Raichvent avatar

Watchers

James Cloos avatar Nguyễn Khánk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.