2021工作中的小知识点3(vue修改网页标题、格式化时间、js挂载vue组件并传参、修改key值、数组找最大值)

1.svg使用

参考链接

2.vue 修改网页标题

1.public下的index.html里修改title  <title>xx系统</title>
2.document.title = "xx系统"

3.下载图片

window.location="图片网络地址"

4.秒转化为 小时分钟秒

 secondsFormat(value) {
      var theTime = parseInt(value); // 秒
      var theTime1 = 0; // 分
      var theTime2 = 0; // 小时
      var theTime3 = 0; // 天

      if (theTime > 60) {
        theTime1 = parseInt(theTime / 60);
        theTime = parseInt(theTime % 60);
        if (theTime1 > 60) {
          theTime2 = parseInt(theTime1 / 60);
          theTime1 = parseInt(theTime1 % 60);
        }
      }
      var result = "" + parseInt(theTime);
      if (theTime1 > 0) {
        result = "" + parseInt(theTime1) + "分" + result;
      }
      if (theTime2 > 0) {
        result = "" + parseInt(theTime2) + "小时" + result;
      }
      return result;
    },

5.秒转化为 天小时分钟秒

  formatSecond(value) {
      const days = Math.floor(value / 86400);
      const hours = Math.floor((value % 86400) / 3600);
      const minutes = Math.floor(((value % 86400) % 3600) / 60);
      const seconds = Math.floor(((value % 86400) % 3600) % 60);
      var forMatDate = "";
      if (days) {
        forMatDate += days + "天";
      }
      if (hours) {
        forMatDate += hours + "小时";
      }
      if (minutes) {
        forMatDate += minutes + "分钟";
      }
      forMatDate += seconds;
      return forMatDate;
    },

7.把时间中的-、/转化

replace(/-/g, "/")
e[0].replace(/\//g, "-");

8.把一位数的时分秒自动填充为两位数

let month='9'
month=("00" + month).substr(-2, 2)

9.javascript 从对象数组中 按字段/属性取最大值或最小值

var array=[
        {
            value: 100
        },
        {
           value: 20
        },
        {
            value: 50
        }];

取最大值:Math.max.apply(Math, array.map((item)=> {return item.value}))
取最小值:Math.min.apply(Math, array.map((item)=> {return item.value}))

10.js在当前时间上加分钟数,得出结果


1.获取当前日期
var date=new Date();
2. 获取当前分钟
var minutes=date.getMinutes();
3. 设置当前时间10分钟前:把当前分钟数+10后的值重新设置为date对象的分钟数
date.setMinutes(minutes+10);
4. 测试
console.log(date.toLocaleString());

11.修改对象key

对象修改建名

12.自定义组件上用v-model传递参数

父组件用 v-model
组件接收用
 model: {
 	prop: 'checked',
    event: 'input'
 	},
props: {
	checked: {
    	default: ''
    	},
	}
通知父组件 this.$emit('change', result)
 model: {
 	prop: 'checked',
    event: 'input'
 	},
props: {
	checked: {
    	default: ''
    	},
    }
通知父组件 this.$emit('input', result)

js挂载vue组件并传参

用js挂载.vue组件/动态创建实例,参考链接
挂载的vue怎么传prop 参考链接

父组件
 let temp="传递的参数"
 let c = document.createElement("div");
            c.id = "echart-layout";
            let Constructor = Vue.extend(weather);
            let toast = new Constructor({ propsData: { viewData: temp } });
            toast.$mount();
            c.appendChild(toast.$el);

子组件 weather
  props: {
    viewData: {
      type: String,
      default: "",
    },
  },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值