Code Monkey home page Code Monkey logo

vue-elm's Introduction

vue-elm

A Vue.js project,仿饿了么网站

构建

# install dependencies

yarn

# serve with hot reload at localhost:9983
yarn dev

# build for production with minification
yarn build

# build for production and view the bundle analyzer report
yarn analyz

开发

接口请求

封装了fetch,只需要在./src/services/urls.js里添加你需要的接口路径,然后在./src/services/services.js里添加接口请求的封装,在你需要请求的地方引入即可,封装例子如下

export function cities (options = {}) {
    return new Promise((resolve, reject) => {
        request({
            method: 'GET',
            url: url.cities,
            param: options,
        }, (res) => {
            resolve(res);
        });
    });
}

组件

需要的公共组件放在./src/components

过滤器

vue可以自定义过滤器,你可以放在./src/filters下

工具类函数

工具类函数写在./src/utils/tools.js里,可定义公共函数

状态管理

vuex,在src/store/modules/添加相应模块的module,写法如下

import { Commit } from 'vuex';
import * as types from '../mutation-types';
import { cities } from '../../services/services';

const state = {
    cities: {
        pinyin: '',
        is_map: false,
        longitude: 0,
        latitude: 0,
        sort: 0,
        area_code: '',
        abbr: '',
        name: '',
        id: 0,
    },
};

const actions = {
    async cities (context, params) {
        const data = await cities(params);
        context.commit(types.CITIES, data);
    },
};

const mutations = {
    [types.CITIES] (state, payload) {
        state.cities = payload || {};
    },
};

export default {
    state,
    mutations,
    actions,
};

相应页面引入

import { mapActions, mapState } from 'vuex';

export default {
    name: 'HelloWorld',
    data () {
        return {
            msg: 'Welcome to Your Vue.js App',
        };
    },
    created () {
        this.cities({ type: 'guess' });
    },
    computed: {
        ...mapState({
            citiesDate: state => state.test.cities,
        }),
    },
    methods: {
        ...mapActions(['cities']),
    },
};

路由

使用的是vue-router,使用见http://router.vuejs.org/zh-cn/index.html

静态文件

静态文件放在./src/assets/下公共的scss和各页面需要的图片和公共js文件、字体等

elm开放api接口文档 element-ui

vue-elm's People

Contributors

sunnyshining avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.