Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas
/
scrm-micro-finance
This project
Loading...
Sign in
Toggle navigation
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
Commit f830ed3b
authored
Apr 25, 2023
by
前端
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
提交20.0代码
1 parent
4250bd7d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
3 deletions
src/main.js
src/plugins/chaining/index.js
src/utils/chaining.js
src/main.js
View file @
f830ed3
...
@@ -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
()
...
...
src/plugins/chaining/index.js
0 → 100644
View file @
f830ed3
// 针对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
src/utils/chaining.js
View file @
f830ed3
export
const
optionalChaining
=
(
obj
,
...
rest
)
=>
{
export
const
optionalChaining
=
(
obj
,
...
rest
)
=>
{
return
rest
.
reduce
((
newObj
,
key
)
=>
newObj
[
key
],
obj
)
}
\ No newline at end of file
\ No newline at end of file
return
rest
.
reduce
((
newObj
,
key
)
=>
newObj
?.[
key
],
obj
)
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment