Prefer default export
时间: 2023-09-29 13:08:38 浏览: 92
ESLint 规则文件
5星 · 资源好评率100%
Sure, I can assist you with that. In JavaScript, a default export allows you to export only a single value or function from a module. This value is considered the "default" export and can be imported without using curly braces.
To create a default export, you can use the `export default` syntax. Here's an example:
```javascript
// myModule.js
const myFunction = () => {
console.log("This is my function.");
};
export default myFunction;
```
In another file, you can import the default export like this:
```javascript
import myFunction from './myModule.js';
myFunction(); // Output: "This is my function."
```
It's important to note that you can only have one default export per module. If you need to export multiple values, you can use named exports instead.
阅读全文