Home > Article > Web Front-end > Export default usage in vue
The export default usage in Vue.js is used to export a component, module or value as the default export. The benefits include simplicity and convenience, single export and cross-component sharing. To use it, you can write export default { // component or value code } in the export file, and import {name of export} from ‘./exported file path’ in the import file.
Export default usage in Vue.js
In Vue.js, export default
Syntax is used to export a component, module or value as the default export. This export differs from named exports in that there can be only one default export and no export name needs to be specified.
Usage
To use export default
in Vue.js, you can follow the following syntax:
<code class="javascript">export default { // 组件、模块或值的代码 };</code>
For example:
<code class="javascript">export default { name: 'MyComponent', template: '<p>This is my component.</p>' };</code>
Benefits
Using export default
has several benefits:
export default
statement, no export name needs to be specified. Import
Exported components, modules, or values using export default
can be imported using the following syntax:
<code class="javascript">import MyComponent from './MyComponent.vue';</code>
MyComponent.vue
is the file path of the exported component.
Example
Let’s look at an example of a component exported using export default
:
MyComponent.vue
<code class="javascript"><template> <p>This is my component.</p> </template> <script> export default { name: 'MyComponent' }; </script></code>
App.vue
<code class="javascript"><template> <MyComponent /> </template> <script> import MyComponent from './MyComponent.vue'; </script></code>
In this example, MyComponent.vue
is exported using export default
A component named MyComponent
is created. In App.vue
, this component is imported and rendered.
The above is the detailed content of Export default usage in vue. For more information, please follow other related articles on the PHP Chinese website!