技术问题总结

2019-03-07  本文已影响0人  谁注册了我的搬砖狗

一.数组类

  1. 怎么将数据组arr[1,2,3] ,arr1[1,2,3,4] 对比提取出4
解答:
var num = arr1.find( item => {
  return !arr.includes(item)
});
num = 4;


二.Vue + element-ui类

  1. Vue配合element-ui中过滤数据 返回html代码的操作
代码如下:

formatter: (row, column, cellValue, index) => {
              return cellValue == 'enable' ? (
                <span style="color:#3267e6">启用</span>
              ) : (
                <span style="color:#e65252">禁用</span>
              )
            }
  1. Vue中的增删改查 调用的表单这个时候我们一般可以封装系统的业务逻辑

代码如下:

 extraButtons:[
 {
          type: 'primary',
          text: '编辑',
          atClick: row => {
            this.extraButtonsHandle(row, '编辑业务')
            return Promise.resolve(false)
          }
        },
        {
          text: '查看',
          atClick: row => {
            this.extraButtonsHandle(row, '查看业务', true)
            return Promise.resolve(false)
          }
        }
]


封装的函数代码如下:

methods:{
   extraButtonsHandle(row, title, isDetail) {
      this.delItem = row
      this.dialogVisible = true
      //点击不同的按钮标题就会不同因为传入的值不同
      this.dialogTitle = title
      //当点击查看看的时候就会 隐藏表单的确定按钮 ,因为编辑按钮没有传入值isDetail是undenfind 隐式转换false
      this.isDetail = isDetail
      this.$nextTick(() => {
        this.$refs.dialogForm.updateForm({
          //解构数据源
          ...row,
          //数据源中的字段和渲染页面的字段不匹配 所以重新返回定义字段(我们只需要值)
          paySysAccessAuthCode: row.paySysAccessAuth.code,
          payApplicationCode: row.payApplication.code
        })
      })


}


三.esa6 新语法

代码:
const {a,b,c} = {a:1 , b:2 ,c:3 ,arr:['money']}
console.log(a) // a = 1
console.log(b) // b = 2
console.log(c)  // c = 3
console.log(arr)  // arr = 'money'
//对象中的解构只要对应键,就能拿到 

代码:
const{a,b,c} = [4,5,6]
console.log(a) // a = 4
console.log(b) // b = 5
console.log(c)  // c = 6
//如果需要单独解构其中的一个也是需要对应位置的(数组的解构需要对应位置)
const{,,c} = [4,5,6]
console.log(c)  // c = 6

四.算法类

  1. 如何计算出1+2+3+。。。+n 用你最熟悉的语言方式
代码:
//递归算法   p是函数的名称
function p(x){
    if(x < 2){
        return 1
  }else {
    return x+ p(x-1)
            }
}

  1. 如何计算出1/2+1/3+。。。。+1/n
代码:
//递归算法 p是函数的名称
function p(x){
  if(x < 2){
    return 0
  }else{
    return 1/x +p(x-1)
  }

}

五 Vue报错点

错误操作:

不要在选项属性或回调上使用比如 `created: () => console.log(this.a)` 或
 `vm.$watch('a', newValue => this.myMethod())`。
因为箭头函数是和父级上下文绑定在一起的,
`this` 不会是如你所预期的 Vue 实例,
经常导致 `Uncaught TypeError: Cannot read property of undefined` 或 `
Uncaught TypeError: this.myMethod is not a function` 之类的错误。

上一篇 下一篇

猜你喜欢

热点阅读