zoukankan      html  css  js  c++  java
  • 非前后端分离项目使用vue继承,提取公共方法和filters

    var vue_fn = {
        filters:{
            formatDate: function (value) {
                if(value==null){
                    return "";
                }
                let date = new Date(value);
                let year = date.getFullYear();
                let month = date.getMonth()+1;
                let day = date.getDate();
                month = month < 10 ? "0"+month:month;
                day = day < 10 ? "0"+day:day;
                date = year+'-'+month+'-'+day;
                return date;
            },
            formatDateTime: function (value) {
                if(value==null){
                    return "";
                }
                let date = new Date(value);
                let year = date.getFullYear();
                let month = date.getMonth()+1;
                let day = date.getDate();
                let h = date.getHours();
                let mm = date.getMinutes();
                let s = date.getSeconds();
                month = month < 10 ? "0"+month:month;
                day = day < 10 ? "0"+day:day;
                date = year+'-'+month+'-'+day+" "+h+":"+mm+":"+s;
                return date;
            }
        },
        methods: {
            showPhoto: function (title, url) {//显示图片
                var json = {
                    "data": [{
                        "alt": title,
                        "src": url,
                    }]
                }
                layer.photos({
                    photos: json //格式见API文档手册页
                    // ,anim: 1 //0-6的选择,指定弹出图片动画类型,默认随机
                });
            }
        }
    }

    子vue,filter可以直接用,method也可以直接this.method名调用

    var childvue1 = new Vue({
        extends : vue_fn,
        el: '#settleDetailDev',
        data: {
        } ,
        mounted: function () {
        },
        methods: {
           showFkpz:function () {
              var _this = this;
              _this.showPhoto("付款凭证","url");
            }
        }
    })

      

      

  • 相关阅读:
    正则表达式实例
    正则表达式理解
    Git初体验
    浏览器加载解析HTML、JS、CSS的过程
    iframe
    纯前端,html页面间传值方式:
    Visual Code 之使用
    seajs使用记
    VBA中Dictionary对象使用(Key,Value)
    存储过程和存储函数和触发器示例
  • 原文地址:https://www.cnblogs.com/mafy/p/11897749.html
Copyright © 2011-2022 走看看