js 语法规则

vue

  • vue 监听
watch: {
     
      'formInline.ruleDeptName' (val){
        console.log("申请单位   "+JSON.stringify(val))
      }
    }
  • 离开路由
beforeRouteLeave (to, from, next) {
    debugger
    this.echartVisible = false
    console.log(to)
    console.log(from)
    next()//一定不要忘记写
  },
  • findIndex()返回满足条件的数组下标
var currentProfileIndex = (profiles|| []).findIndex((profile) => profile.id === currentProfile .id);
  • 字符串 根据 逗号 拆分成 数组
var s = "abc,abcd,aaa";
ss = s.split(",");// 在每个逗号(,)处进行分解。
  • 数组成员 是 数字类型
var s = "abc,abcd,aaa";
ss = s.split(",").map(Number)
  • 设置 对象 成员的数值
this.$set(this.formInline,'cz',this.formInline.cz.split(","))
  • 时间格式
yyyy-MM-dd HH:mm:ss

			
            
  • 时间得到 是毫秒数
new Date().getTime()   

数组操作

  • 放入 push
this.editableTabs.push({
  title: 'New Tab',
  name: newTabName,
  content: 'New Tab content'
});
  • 遍历
this.dataList.forEach((item, index) => {  
              var tbCol = {}
              tbCol.fieldCnName = item.fieldCnName
            })

  • 去重
let array = Array.from(new Set(list))
  • 删除数组中的指定对象 或者 删除 对象的指定属性
let parA = this.tableData.fieldData[i].parA;
this.$delete(this.tableData.fieldData[i],'parA');

this.$delete(param,'defaultExtraVal');
  • 设置数组的第几项
this.$set(this.params,i,param)
  • 数组是否包含某个元素 查找
var fruits = ["Banana", "Orange", "Apple", "Mango"];

var a = fruits.indexOf("Apple"); // 2
  • 数组过滤查找
   let mainTab = this.mainTabs.filter(item => item.name.toString() == tab.name)[0]

判空


//字符串对象
export function stringIsEmpty(parA){
  //为空返回true
  if(parA == null || typeof (parA) == "undefined" || parA == "" ){
    return true
  }else{
    if(isString(parA)){
      if(parA.trim() == ""){
        return true
      }
    }
    return false
  }
}
//判断是否为原始类型:字符串、数字或者布尔类型,
export function isString(obj){
  return  typeof(obj) === 'string'?true:false;
}
//数组对象
export function  arrIsEmpty(arr){
  //为空返回true
  if(arr == null ||arr == undefined || arr.length <= 0){
    return true
  }
  return false
}

//对象为空
export function isEmptyObject(obj){
  if(JSON.stringify(obj)=='{}' || obj == null){
    return true
  }
  return false
}

你可能感兴趣的:(js 语法规则)