巨常用前端技术汇总

115 阅读1分钟

1-判断对象是否为全空

var object = this.info;
      var isEmpty = true;
  Object.keys(object).forEach(function(x) {
      if(object[x] != null && object[x] != ""){
        isEmpty = false;
      }
  });
  if(isEmpty){//值全为空
     console.log('都是空')
  }else{
         console.log('都不是空')
  }

2-头部url方法传参封装方法

mounted() {
    if (this.getQueryString("BZGL_ID")) {
      this.BZGL_ID = this.getQueryString("BZGL_ID");
    } else {
      this.$alert('缺少必要参数', '提示', {
        confirmButtonText: '确定',
      });
    }
    this.allDetail();
    this.url = url;
  },
​
getQueryString: function (name) {
      var urls;
      if (
        window.location.href.indexOf("?") !=
        window.location.href.lastIndexOf("?")
      ) {
        urls = window.location.href.replace(/?/g, "&").replace(/^.*?&/, "");
      } else {
        urls = window.location.href.replace(/^.*?/, "");
      }
​
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
      var r = ("?" + urls).substr(1).match(reg);
      if (r != null) return decodeURI(r[2]);
      return null;
    },

3-vue a链接下载参数封装

writeUploadFile() {
      const linkNode = document.createElement('a');
      linkNode.style.display = 'none';
      linkNode.href = this.url+"/jhgl/reportExport?guid=123456";
      document.body.appendChild(linkNode);
      linkNode.click();
      URL.revokeObjectURL(linkNode.href);
      document.body.removeChild(linkNode);
    },

4-vue element 图片悬浮放大

<el-popover placement="top-start" width="200" trigger="hover" > <img class="img1" :src="qrcodeUrl" style="width:200px;height:200px;"> <img slot="reference" class="img2" :src="qrcodeUrl" style="max-width: 50px;max-height: 100px"> </el-popover>

5-vue 8080端口占用问题

1-// 查询端口 比如8080

lsof -i :8080

查询到

COMMAND   PID USER   FD   TYPE            DEVICE SIZE/OFF NODE NAME

node    46599  qiu   24u  XXX          xxx

2-// 杀死端口PID进程号

sudo kill -9 87972
   

6-年月日,时分秒时间转换

getNowFormatDate(){
      let date = new Date(),
        year = date.getFullYear(), //获取完整的年份(4位)
        month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
        strDate = date.getDate(), // 获取当前日(1-31)
        hour = date.getHours(), //获取当前小时(0 ~ 23)
        minute = date.getMinutes(), //获取当前分钟(0 ~ 59)
        second = date.getSeconds() //获取当前秒数(0 ~ 59)

      if (month >= 1 && month <= 9) month = '0' + month // 如果月份是个位数,在前面补0
      if (strDate >= 0 && strDate <= 9) strDate = '0' + strDate // 如果日是个位数,在前面补0
      if (minute >= 0 && minute <= 9) minute = '0' + minute // 如果分是个位数,在前面0
      if (second >= 0 && second <= 9) second = '0' + second // 如果秒是个位数,在前面0

      let currentdate = `${year}${month}${strDate}${hour}${minute}${second}`
      return currentdate
      
    }

7-生成32位的随机字符串

// import { TRUE } from "node-sass";
// 生成32位的随机字符串
export const getGuid = () => {
  let guid = "";
  for (var i = 1; i <= 32; i++) {
    var n = Math.floor(Math.random() * 16.0).toString(16);
    guid += n;
    if (i == 8 || i == 12 || i == 16 || i == 20) guid += "-";
  }
  return guid;
};