{"id":20542177,"url":"https://github.com/weivea/vue-twig","last_synced_at":"2025-09-07T04:36:53.857Z","repository":{"id":83302822,"uuid":"73352296","full_name":"weivea/vue-twig","owner":"weivea","description":"用于vue.js的数据model层插件","archived":false,"fork":false,"pushed_at":"2017-01-04T10:24:41.000Z","size":638,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-13T09:56:03.520Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weivea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-10T06:10:59.000Z","updated_at":"2018-06-13T13:44:48.000Z","dependencies_parsed_at":"2023-05-05T11:01:35.091Z","dependency_job_id":null,"html_url":"https://github.com/weivea/vue-twig","commit_stats":{"total_commits":26,"total_committers":1,"mean_commits":26.0,"dds":0.0,"last_synced_commit":"4c3a211bd9505cc3e111914f90db55f95b6e6d68"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/weivea/vue-twig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fvue-twig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fvue-twig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fvue-twig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fvue-twig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weivea","download_url":"https://codeload.github.com/weivea/vue-twig/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Fvue-twig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273997100,"owners_count":25204473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T01:29:39.303Z","updated_at":"2025-09-07T04:36:53.822Z","avatar_url":"https://github.com/weivea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vue-twig\n用于vue.js的数据mvc的model层插件,区别于单项数据流的另一种体验,\n属于mvc思想的优化,个人这么理解\n同时提供localStorage,sessionStorage本地存储功能\n\n## demo\ntodomvc:https://weivea.github.io/vue-twig/\n\n## install\n\n```\nnpm install vue-twig --save\n```\n\n## usage\n\n\n```\n\n//初始化\nimport Vue from 'vue'\nimport twig from 'vue-twig'\nimport co from 'co'  //运行Generator函数需要,不需要则不引入\nimport app from './app'\n\nvar model = {\n              key: \"model名\",\n              saveType: twig.saveType.localStorage,//存储类型.localStorage/sessionStorage\n              dataFun: function (data) {//可以是普通函数,Generator函数(需要co模块),async函数\n                //data:缓存的数据\n\n                //生成初始化数据\n\n                return data;//返回初始化的数据\n              }\n            }\n\nVue.use(twig, model, [co])//co为可选参数\n//或\nVue.use(twig, [model1,model2,moel3 ...],[co])\n\n//数据初始化成功后创建应用实例\ntwig.ready(function () {\n  window._App = new Vue({\n      el: '#container',\n      components: {\n        app\n      },\n      render (h) {\n        return (\n          \u003capp/\u003e\n        )\n      }\n    })\n})\n\n\n\n\n//组件接入子model\n//app.js\n\nexport default {\n  name: 'app',\n  data: function () {\n    //接入twig,可选择性接入\n    var twigs= this.$twigWarp({\n      session: this.$twig.session,\n      storage: this.$twig.storage,\n      dataTree: this.$twig.dataTree\n    })\n\n    //私有data\n    var privates={\n        a:1,\n        b:2\n    }\n    return Object.assign(twigs,privates)\n  },\n\n  //只读型接入介，\n  computed: {\n      formA: function () {\n          return this.$twig.session.form.a\n      }\n  },\n  ...\n}\n\n```\n\n### warning\n\n1:twig的接入具有非常大的灵活性,随意操作也会带来问题,像redux也是有『数据操作强约束』的,不能改变\nstore的数据结构,twig同样如此;\n\n2:data中接入的twig数据要求是对象(索引类型),接入值类型不能触发深入式响应,当然计算属性可以接入值类型;\n\n3:被接入的twig根节点强制不允许被赋值操作;\n\n## 描述\n\ntwig并不是一个\"开发便利性\",\"性能\"都超越vuex或其它流程插件的这样一个定位东西.\ntwig是在mvc的开发思想上,做了进一步模块功能的开发细分:以此达到优化开发流程的目的.\n提供一种异于『绝对的单项数据流』的新的开发思维卡供选择\n\n大致思想如下:\n+ 应用总的数据由twig管理,根据功能分成不同的model;\n+ web应用根据功能和视图划分为不同的组件(component),接入对应的model,形成映射关系. 在单个组件中,只关心组建内model的数据;\n+ 组件的view由model数据驱动,对组件内model的操作,就是对twig中model的操作;\n+ 单个组建内部,使用什么样的数据操作流程都没有关系;\n\n*数据接入*\n![数据接入](./img/1.pic.jpg \"数据接入\")\n*接入简化*\n![接入简化](./img/3.pic.jpg \"接入简化\")\n*深入分解*\n![深入分解](./img/2.pic.jpg \"深入分解\")\n\n固有的mvc因为在复杂页业务场景不好管理model与view之间的关系,twig将程序整体划分为一个一个小的相对独立的子mvc,这样一定程度的解决了\n原有mvc模式的复杂性,又保留了model与view的直接联系.\n\n这里借鉴了angular.js的rootScope的思想.只是我们每个组件(component/controller)只接触和自己相关的数据;\n\n基于vue深入式相应的特性,组件对model的修改,可触发所有接入该model的组件view的更新;\n\n程序的设计应以model数据结构为准则, 组件(component)不得修改model的数据结构（flex,redux 亦然）,\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Fvue-twig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweivea%2Fvue-twig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Fvue-twig/lists"}