当前位置:网站首页>Es11 new methods: dynamic import(), bigint, globalthis, optional chain, and null value merging operator
Es11 new methods: dynamic import(), bigint, globalthis, optional chain, and null value merging operator
2022-06-25 06:04:00 【taoqidejingling】
Catalog
Dynamic Import() Dynamic import
BigInt Represents an integer of any precision
globalThis In the global scope this
Optional chain Optional chaining ?.
Dynamic Import() Dynamic import
- Load on demand
- In the use of webpack When packing , The files loaded on demand will be packaged into a small module
- When more components are required to be loaded asynchronously , More individual files will be generated , For front-end performance , Although each file is smaller , But it may mean more network connection setup and shutdown costs , In front-end Optimization Practice , It is often necessary to strike a balance between the number of files and the size of a single file
// Sample code
<template>
<section>
<button @click="submit"> Submit </button>
</section>
</template>
<script>
export default {
name: 'Test',
methods: {
submit(){
// Load on demand
import(/* webpackChunkName: "a" */'@/assets/a.json').then(mod => {
console.log(mod)
})
}
}
}
</script>// src/assets/a.json
{
"a": "a"
} 
- vue Dynamic import in the project ( Load on demand ) You can also use the following methods , Such as importing components or routing
const Home = () => import('@/components/home')BigInt Represents an integer of any precision
- ES10 New original data type , Can represent very long data , Can exceed 2 Of 53 Power
BigInt There are two ways
1) Add... After the number n
const bigInt = 9007199254740993n
console.log(bigInt)
console.log(typeof bigInt) // bigint
console.log(1n == 1) // true
console.log(1n === 1) // false2) Use BigInt function
const bigIntNum = BigInt(9007199254740993n)
console.log(bigIntNum)globalThis In the global scope this
- In the global scope this Namely globalThis
- It can be used safely globalThis, Don't worry about its operating environment
- self: Open any web page , The browser will first create a window , This window is a window object , It's also js Run the attached global environment object and global scope object
- self Refers to the window itself , The object it returns follows the window The object is as like as two peas.
- Because of this ,window Object common methods and functions can be used self Instead of window
self.setTimeout(() => {
console.log(123, self)
}, 1000)Optional chain Optional chaining ?.
- When querying multi-level objects , There is no need for redundant pre checks
- Choose... In the chain ? Indicates that if the expression to the left of the question mark has a value , Will continue to query the fields after the question mark
const user = {
address: {
street: 'xx The street ',
getNum() {
return '80 Number '
}
}
}
const street2 = user?.address?.street
const num2 = user?.address?.getNum?.()
console.log(street2, num2)Null merge operator ??
- Null merge operator (??) It's a logical operator
- When the left-hand operands are null or undefined when , It returns the right operand . Otherwise, return the left-hand operand
- When we query a property , Come across , If there is no such attribute, a default value will be set
- Null merge operator ??, Only when the first item is null or undefined when , Setting the default value is valid
// false 0 Invalid
const b
const a = b ?? 123
console.log(a)
边栏推荐
- C switch nested syntax
- Various errors and solutions encountered when deploying SAP ui5 application to ABAP server with SAP Fiori tools
- The locally developed SAP ui5 application is deployed to the ABAP server to perform error analysis
- Do you know what a three-tier architecture is?
- 钱堂教育的证券账户安全吗?靠谱吗?
- No one reads the series. Source code analysis of copyonwritearraylist
- By inserting a section break, the word header, footer, and page number can start from any page
- How SAP ui5 device type detection device API works
- Guava immutable set
- Go language map sorting (key/value sorting)
猜你喜欢

MySQL tuning --01--- optimization steps and system performance parameters

No one reads the series. Source code analysis of copyonwritearraylist
SAP ui5 beginner tutorial No. 27 - unit test tool quNit introduction trial version for SAP ui5 application

Uni app wechat applet customer service chat function

Gavin's insight on transformer live class - line by line analysis and field experiment analysis of insurance BOT microservice code of insurance industry in the actual combat of Rasa dialogue robot pro
Technology inventory: Technology Evolution and Future Trend Outlook of cloud native Middleware

Mongodb basic concept learning - set
SAP Fiori tools and corresponding cli (command line interface)

Getting started with Silverlight development 1

50 days countdown! Are you ready for the Landbridge cup provincial tournament?
随机推荐
How SAP ui5 device type detection device API works
Ping command – test network connectivity between hosts
Folding mobile phones are expected to explode, or help Samsung compete with apple and Chinese mobile phones
Mongodb basic concept learning - Documentation
D compile time reflection
Find command – find and search for files
[interview with a large factory] meituan had two meetings. Was there a surprise in the end?
Understanding the dynamic mode of mongodb document
The simplest way to tell you is to hash and not hash
Uname command – displays system information
You can't specify target table for update in from clause error in MySQL
Tutorial 35 of SAP ui5 application development - how to deploy locally developed SAP ui5 applications to ABAP server for trial reading
Wireless industrial Internet of things data monitoring terminal
Timed thread pool
Try with resource close resource flow
No one reads the series. Source code analysis of copyonwritearraylist
Day22(File,DiGui,FileOutputStream)
What is SAP sup - Sybase unwired platform
Distributed solar photovoltaic inverter monitoring
钱堂教育的证券账户安全吗?靠谱吗?