Commit f830ed3b by 前端

提交20.0代码

1 parent 4250bd7d
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
*/ */
import Vue from 'vue' import Vue from 'vue'
import apis from './api' import apis from './api'
import {optionalChaining} from './utils/chaining' // 针对template模板中使用可选链操作符
// import chaining from '@/plugins/chaining'
import { optionalChaining } from './utils/chaining'
import './public-path' import './public-path'
import '@/assets/css/public.scss' import '@/assets/css/public.scss'
import '@/components' import '@/components'
...@@ -19,6 +21,7 @@ import { start } from '@/setup' ...@@ -19,6 +21,7 @@ import { start } from '@/setup'
Vue.config.productionTip = false Vue.config.productionTip = false
Vue.prototype.$apis = apis Vue.prototype.$apis = apis
Vue.prototype.$$ = optionalChaining Vue.prototype.$$ = optionalChaining
// Vue.use(chaining)
Vue.prototype.size = 'small' Vue.prototype.size = 'small'
Vue.prototype.$EventBus = new Vue() Vue.prototype.$EventBus = new Vue()
start() start()
......
// 针对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 || ""
}
// const test = (obj, ...rest) => {
// let tmp = obj
// for (const key in rest) {
// const name = rest[key]
// tmp = tmp?.[name]
// }
// return tmp || ''
// }
// 添加实例方法
vue.prototype.$$ = optionalChaining
// vue.prototype.$sy = test
}
}
export default chaining
export const optionalChaining = (obj, ...rest) => { export const optionalChaining = (obj, ...rest) => {
return rest.reduce((newObj, key) => newObj[key], obj) return rest.reduce((newObj, key) => newObj?.[key], obj)
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!