基于webpack的vue语法糖实现思路

前言:

          最近2年一直在用vue做前端,发现vue写出来的代码可维护性比较高,但是同样一个功能代码行数比较多。

          就拿一个普通的表单来说,先写template,然后定义data,然后在写校验,然后写method,确实有点麻烦了。

          就想着有没有一种办法,做一种语法糖出来,保证vue原生代码支持的情况下把简单的功能简化。

          在开源中国看到百度的https://gitee.com/baidu/amis  amis项目,他使用json来画页面,代码非常的少,但是因为不支持自定义js扩展,所以做很多外部系统不是很好用。

          结合我做 fhs framework pagex模块的经验,提出了以下的思路。

小目标

比如我写一个表单页面,我可以这样写:

<template>
<pagex>
{
    id:"addForm",
    attr:{"class":"formClass",style:"with:100%"}
    config: {saveUrl: '/data/tank_owner/save',infoUrl:'/data/tank_owner/findById'},
    hook:{onSubmit:addFormOnSubmit},
    type:'form',
    child: [
        {
            title: '基础信息',
            type: 'group',
        },
        {
            title: '联系人',
            name: 'linkMan',
            type: 'input',
            required: true,
            dataType:'s-1-32'
        },
        {
            title: '联系地址',
            type: 'addressSelect',
            required: true,
            multiple : false,
        },
        {
            title:'备注',
            type:'textarea',
            name:'remark'
        },
        {
            title:'人员列表',
            data:'tableData',
            type:'table',
            columns: [
             {
                title: '姓名',
                name:'userName'
             },
             {
                title: '操作',
                template: `<template slot-scope="scope">
                <router-link
               v-auth="2"
               :to="{
                 path: '/dataCustomerManagerEdit',
                 query: { id: scope.row.userId}
               }"
             >
              编辑
             </router-link>
             </template>`,*/
             }
            ],
        },
   ]
}
</pagex>
</template>
<script>
export default {
  data() {
    return {
        tableData:[]
    }
  },
  async created() {
    await this._getTableData();
  },
  methods: {
    addFormOnSubmit(){
        let needSubForm = clone(this.addForm);
        if(!needSubForm.linkMan){
           needSubForm.linkMan = '我是默认值'
        }
        return needSubForm;
    },
    _getTableData(){
       this.tableData = [{userName:'zhangsan',"userid":1}];
    },
  }
}
</script>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SugarWorker —— 轻松的使用web多线程技术; webWorker var lsitWorker = new Worker('core/listWorker.js'); lsitWorker.onmessage = function(e){          if(e.data){         listWorker.postMessage('new test data');     }     ...(response)     console.log(e);     lsitWorker.terminate(); }; listWorker.onerror = function(e){     ...(response)     console.error(e); }; listWorker.postMessage('test data'); SugarWorker work('core/listWorker.js')     .back(function(e){                  if(e.data){             e.post('new test data');         }         ...(response)         console.log(e);         e.end();     })     .err(function(e){         ...(response)         console.error(e);     })     .post('test data'); SugarWorker还支持事件定义,方便监听另一条线程的状态 work('core/test.js')     .back(function(e){         console.log(e);     })     .set('loading',function(e){         console.log('loading');         console.log(e);     })     .post('test data'); //test.js onmessage = function(e){     postMessage({         eventType : 'loading',         data : {...}         //some datas          }); } 通过worker线程返回对象,添加eventType属性,可以在主线程触发定义的事件; 添加eventType的返回数据,不会触发主线程back方法; 更多使用方法请查看:https://github.com/kirakiray/SugarWorker 标签:SugarWorker
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值