Skip to content
  • Projects
  • Groups
  • Snippets
  • Help

韦竞 / dj-carlife-web

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • dj-carlife-web
  • src
  • plugin
  • chaining
  • index.js
  • 韦竞's avatar
    add · b0ecfd63
    韦竞 committed Aug 29, 2022
    b0ecfd63
index.js 396 Bytes
RawBlameHistoryPermalink
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// 针对template模板中使用可选链操作符
const chaining = {
  install(vue) {
    const optionalChaining = (obj, ...rest) => {
      let tmp = obj
      for (const key in rest) {
        const name = rest[key]
        tmp = tmp?.[name]
      }
      return tmp || ''
    }
    // 添加实例方法
    vue.prototype.$$ = optionalChaining
  }
}

export default chaining