部分记录

224 阅读2分钟

自定义校验规则

const checkSpace = (rule, value, callback) => {
  if (!value.trim()) {
    callback(new Error('请输入真实姓名'))
  } else {
    callback()
  }
}
​
export default {
}
rules: {
        loginName: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        userName: [
          { required: true, message: '请输入真实姓名', trigger: 'blur' },
          { validator: checkSpace, trigger: 'blur' }
        ],
        isAdmin: [
          { required: true, message: '请选择用户类型', trigger: 'change' }
        ],
        deptId: [
          { required: true, message: '请选择所属组织', trigger: 'change' }
        ]
      }

父组件table列表

子组件添加修改

父组件...
<custom-update ref="custom-update" v-model="dialogVisibleUpdate" :routename="routeName" :addtype="addType" @complete="getList" />
    父组件接受complete并调用getList方法  getList为获取table列表的方法
    
     handleCreate() { //父组件点击按钮打开
      this.addType = true
      this.$refs['custom-update'].formData = this.$refs['custom-     update'].$options.data().formData
      this.$refs['custom-update'].defaultCheckedKeys = []
      this.dialogVisibleUpdate = true
    },
子组件中..
  async insertAttributes() {
      const data = this.getSaveAttrParams()
      await insertAttributes(data)
      this.hide()
      this.$emit('complete')
      this.$message({
        type: 'success',
        message: '新增成功!'
      })
    },
        再完成新增或修改之后,向父组件传值complete

校验只能输入正整数

@input.native="handleAiFormTwoInput($event, 'pointsSendF2')"@blur="pointsText($event)"handleAiFormTwoInput(e,prop){ // 校验只能输入正整数
      if (e.target.value.includes('.')) {
        e.target.value = e.target.value.replace('.', '')
      }
      e.target.value = e.target.value.replace(/[^-\d]/g, '')
      if (e.target.value.includes('-')) {
        console.log('1111---')
        e.target.value = e.target.value.replace('-', '')
      }
      // this.ruleForm[prop] = e.target.value
    },
    pointsText(e){
      console.log(e.target.value)
      let boo = new RegExp("^[1-9][0-9]*$").test(e.target.value)
      if(!boo){
        this.$message({
              type: 'error',
              message: '请输入正整数!'
            })
      }
    },

git

分支合并

blog.csdn.net/qq_20042935…

新建分支 : git branch 分支名

切换分支: git checkout 分支名

将分支a合并到分支b : 1.先切换到分支b 2.git merge a 3.提交git push origin b

git push -u origin dev-help

深拷贝
export default function deepClone(target) {
  'use strict'
  if (target === null) {
    throw new TypeError('Cannot convert undefined or null to object')
  }
​
  target = Object(target)
  for (var index = 1; index < arguments.length; index++) {
    var source = arguments[index]
    if (source !== null) {
      for (var key in source) {
        // console.log(typeof source[key],typeof source[key] === 'function' ,key, source[key])
        // if(typeof source[key] === 'function') {
        //   console.log(source)
        // }
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          if (typeof (source[key]) === 'object' && target[key]) {
            deepClone(target[key], source[key])
          } else {
            if (Object.prototype.toString.call(source[key]) === '[object Array]' || Object.prototype.toString.call(source[key]) === '[object Object]') {
              // deepClone(target[key], source[key])
              target[key] = JSON.parse(JSON.stringify(source[key]))
            } else {
              target[key] = source[key]
            }
          }
        }
      }
    }
  }
  return target
}
处理标签数
    // // 处理标签树
    fathAsyncTree(tree = [], children = 'children') {
      return tree.map(item => {
        item.isAppend = false
        item.isEdit = false
        item.addNodeName = undefined
        item.editNodeName = this.getTreeLabelNameText(item)
        if (item[children] && item[children].length > 0) {
          item[children] = this.fathAsyncTree(item[children])
        } else {
          return item
        }
        return item
      })
    },
时间戳
timestamp: new Date().getTime()
md5加密
npm MD5
import md5 from 'md5'
var psd = md5(password)               默认32位小写
password: psd.substring(8, 24)        16位小写是截取32中的一部分
求数组最大值
  const computeXAvgLine = function() {
        let sum = 0
        data.forEach(function(item) {
          sum = Math.max(sum, item[0])
        })
        return sum
      }

echarts折线图个性化填充、线条、拐点样式

www.it610.com/article/129… 上方显示数据

series: [
            {
                name:systemName[0],
                type:'line',
                symbol:'star',//拐点样式
                symbolSize: 8,//拐点大小
                itemStyle : {
                    normal : {
                        lineStyle:{
                            width:3,//折线宽度
                            color:"#FF0000"//折线颜色
                        }
                    }
                },
                data:data[0]
            }
]
路由传参 解决刷新页面路由对象丢失问题

query

由于传的有对象 当刷新页面后 url解析不了对象 so数据丢失,

解决:

 this.$router.push({
          name:'crowdDetails',
          query:{
          count: res.data,
          params:JSON.stringify(params),
          formDatcrowd: JSON.stringify(this.setBtnformData(this.customersList.targetList,this.customersQuery.target))
          }})  穿的时候把对象解析JSON.stringify为字符串
​
const params = JSON.parse(this.$route.query.params); 用的时候再转成对象
这样刷新后url上面还是存在字符串值 再重新渲染JSON.parse解析
如果不用JSON.stringify转换,传的有对象的话 url上将识别不了 [Object,Object]