laoshu133
V2EX  ›  Vue.js

V-Model: 一个 ng-resource 风格的 Vue.js 模型库

  •  
  •   laoshu133 · Dec 11, 2016 · 2424 views
    This topic created in 3454 days ago, the information mentioned may be changed or developed.

    使用 Vue.js 开发后台过程中每个模块都需要写大量重复代码,尝试用过 vue-resource 并不是很好用,还有诸多 Bug ,于是自己动手造了一个轮子:

    v-model ( https://github.com/laoshu133/v-model)

    代码风格趋近于 ng-resource,易于上手 😄

    举例:

    const PostModel = Model.extend('/posts/:id', {
        publish: { method: 'POST' }
    }, {
        EDITING: 0,
        PUBLISHED: 1
    });
    
    const app = new Vue({
        el: '#app',
        data: {
            post: new PostModel({
                status: PostModel.EDITING,
                content: '',
                title: ''
            })
        },
        methods: {
            load(id) {
                this.post = PostModel.get({
                    id: id
                });
    
                return this.post.$promise;
            },
            save(data) {
                return this.post.$save(data);
            }
        }
    });
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1437 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 16:59 · PVG 00:59 · LAX 09:59 · JFK 12:59
    ♥ Do have faith in what you're doing.