zoukankan      html  css  js  c++  java
  • 获取对应天数的方法简单封装--更新

    获取对应天数简单的封装了一下

    没封装前:


     封装后:


    封装代码:

    新建一个名字为utility的js文件
    this.ruleForm.weekValue && this.ruleForm.weekValue1这里没有封装下次用起成一样的名字就可以了
    
    //获取开始日期对应星期几,这时就会用到data中定义的空字符串接收
    export function getWeekStart(
        date,
        dayOne,
        dayTwo,
        dayThree,
        dayFour,
        dayFive,
        daySix,
        daySeven
    ) {
        if (date.getDay() == 0) this.ruleForm.weekValue = dayOne;
        if (date.getDay() == 1) this.ruleForm.weekValue = dayTwo;
        if (date.getDay() == 2) this.ruleForm.weekValue = dayThree;
        if (date.getDay() == 3) this.ruleForm.weekValue = dayFour;
        if (date.getDay() == 4) this.ruleForm.weekValue = dayFive;
        if (date.getDay() == 5) this.ruleForm.weekValue = daySix;
        if (date.getDay() == 6) this.ruleForm.weekValue = daySeven;
    }
    
    
    //获取结束日期对应星期几,这时就会用到data中定义的空字符串接收
    export function getWeekEnd(
        date,
        dayOne,
        dayTwo,
        dayThree,
        dayFour,
        dayFive,
        daySix,
        daySeven
    ) {
        if (date.getDay() == 0) this.ruleForm.weekValue1 = dayOne;
        if (date.getDay() == 1) this.ruleForm.weekValue1 = dayTwo;
        if (date.getDay() == 2) this.ruleForm.weekValue1 = dayThree;
        if (date.getDay() == 3) this.ruleForm.weekValue1 = dayFour;
        if (date.getDay() == 4) this.ruleForm.weekValue1 = dayFive;
        if (date.getDay() == 5) this.ruleForm.weekValue1 = daySix;
        if (date.getDay() == 6) this.ruleForm.weekValue1 = daySeven;
    }
    export default {
        getWeekStart,
        getWeekEnd
    };
    main.js中引入刚刚的js文件
    
    并给原型添加新属性后使用
    
    需要解构赋值
    
    import { getWeekStart } from "./common/utility/utility.js";
    import { getWeekEnd } from "./common/utility/utility.js";
    Vue.prototype.$getWeekStart = getWeekStart;
    Vue.prototype.$getWeekEnd = getWeekEnd;
    对应组件中使用
    事件中:
    changeDate(val) {
          this.$getWeekStart(val[0], "0", "1", "2", "3", "4", "5", "6");
          this.$getWeekEnd(val[1], "0", "1", "2", "3", "4", "5", "6");
          console.log("获取周-", this.ruleForm.weekValue, this.ruleForm.weekValue1);
        }
  • 相关阅读:
    MFC中char*,string和CString之间的转换
    图像分割之(四)OpenCV的GrabCut函数使用和源码解读
    自然图像抠图/视频抠像技术发展情况梳理
    OpenCV混合高斯模型函数注释说明
    Effective STL 为包含指针的关联容器指定比较类型
    vs2010修改状态栏的CStatusBar指针的的SetPaneText()方法时死活不对问题
    windows c/c++ 代码运行时间,毫秒级
    【Math】根据置信度、样本数相关推导过程
    宝宝加减法出题小程序
    混淆矩阵
  • 原文地址:https://www.cnblogs.com/home-/p/11794153.html
Copyright © 2011-2022 走看看