笔记

作者: 嘤夏影 | 来源:发表于2023-06-24 14:12 被阅读0次

    EventBus

    1、新建事件总线event-bus.js

    import Vue from 'vue'
    export const EventBus = new Vue()
    

    2、A组件内a方法需要被B组件调用

    import { EventBus } from '@/utils/eventBus'
    mounted() {
      // 注册
      EventBus.$on('useA', () => {
        this.a()
      })
    },
    destroyed() {
      // 销毁
      EventBus.$off('useA')
    }
    

    3、B组件调用A组件a方法

    import { EventBus } from '@/utils/eventBus'
    EventBus.$emit('useA')
    

    简写

    bad:
    if(res.data && res.data.rows){
      res.data.rows.forEach(element => {})
    }
    
    good:
    res.data?.rows?.forEach(element => {})
    
    // 在 ES6 中新增了class,绑定的方法需要绑定 this,如果是箭头函数就不需要绑定 this
    bad:
    let self = this
    
    good:
    this.handleAccept.bind(this)
    

    函数加入注释

    /**
     * 根据编码获取紧急症
     * @param {String} newSelectItem 选择选项
     * @param {number} udfcodes 入参code
     * @param {function} callback 回调函数
     */
    getTabooData(newSelectItem, udfcodes, callback) {
        // ...
    }
    

    Promise

    func(){
      return new Promise((resolve,reject) => {
        request().then((res) =>{
          resolve()
        },() => {
          reject()
        })
      })
    }
    
      try{
        await this.func(item,[item.udfcode])
      } catch(error) {
        console.error(error)
      }
    

    commit规范

    commit 的类别,只允许使用下面7个标识。

    feat:新功能(feature)
    fix:修补bug
    docs:文档(documentation)
    style: 格式(不影响代码运行的变动)
    refactor:重构(即不是新增功能,也不是修改bug的代码变动)
    chore:构建过程或辅助工具的变动

    相关文章

      网友评论

          本文标题:笔记

          本文链接:https://www.haomeiwen.com/subject/dqjbydtx.html