V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
laoshu133
V2EX  ›  Vue.js

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

  •  
  •   laoshu133 · 2016-12-11 23:50:48 +08:00 · 1878 次点击
    这是一个创建于 2686 天前的主题,其中的信息可能已经有所发展或是发生改变。

    使用 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);
            }
        }
    });
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   907 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 21:03 · PVG 05:03 · LAX 14:03 · JFK 17:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.