转载链接:https://www.cnblogs.com/zhangrenjie/p/15015684.html
延申阅读:可选链操作符、空值运算符
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
module.exports = { plugins: [ '@babel/plugin-proposal-optional-chaining', '@babel/plugin-proposal-nullish-coalescing-operator' ] }
export default { install (Vue) { const optionalChaining = (obj, ...rest) => { let temp = obj for(const key in rest) { temp = temp?.[rest[key]] } return temp } vue.prototype.$chaining= optionalChaining } }
import Vue from 'vue' import Chaining from 'chaining'
Vue.use(Chaining)
<template> <div>{{$$(obj, 'first', 'second') }}</div> </template>
|