简体   繁体   English

进出口报表

[英]import and export statements

I am new to Vue and have previously used React to build small apps.我是 Vue 新手,之前曾使用 React 构建小型应用程序。

Now, I was going through through the boilerplate code for Vue现在,我正在浏览 Vue 的样板代码

Consider this app.vue考虑这个 app.vue

<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
  </div>
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'

export default {
  name: 'app',
  components: {
    HelloWorld
  }
}
</script>

Here, I am unable to comprehend following things related to import and export.在这里,我无法理解以下与进出口有关的事情。

Starting from the beginning从头开始

  <HelloWorld msg="Welcome to Your Vue.js App"/>

here it seems we passing props to our child component.这里似乎我们将道具传递给我们的子组件。

In react, we used to import statements at the top of the app and then use it in our stateful or stateless component but in contrast, in the above code snippet we are importing it after inside the script tag so as JS compiles the code, how would it know what在 react 中,我们曾经在应用程序顶部导入语句,然后在我们的有状态或无状态组件中使用它,但相比之下,在上面的代码片段中,我们在 script 标签之后导入它,以便 JS 编译代码,如何它会知道什么

  <HelloWorld msg="Welcome to Your Vue.js App"/>

is HelloWorld?是你好世界吗? since it is declared afterwards.因为它是在之后宣布的。

Secondly, I have always worked with exporting and importing functions/classes and this is different and now for me to comprehend.其次,我一直在导出和导入函数/类,这是不同的,现在让我理解。 Consider this children component考虑这个子组件

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  }
}
</script>

Here, I am unable to comprehend what is happening in export default?在这里,我无法理解导出默认值发生了什么? I know what export default does but like what is the significance of having properties like name and props inside it?我知道 export default 的作用,但喜欢在其中包含 name 和 props 等属性的意义是什么?

It's the way Vue is structured.这是 Vue 的结构方式。 The export default part that you write in the bottom is the part you import/export to the Vue ecosystem (and to your components), this is an ES6/ES2015 feature(module system), one thing to note that the structure you are using is called Single File Components (.vue files).您在底部编写的导出默认部分是您导入/导出到 Vue 生态系统(以及您的组件)的部分,这是 ES6/ES2015 功能(模块系统),需要注意的是您正在使用的结构称为单文件组件(.vue 文件)。

One great thing about single file components that I like is that you can import another component within the script tag (See: Component Registration) , just above export default, then you can reference it in the export default object(exposing it to your component).我喜欢的单个文件组件的一大优点是您可以在脚本标记中导入另一个组件(请参阅:组件注册) ,就在导出默认值之上,然后您可以在导出默认对象中引用它(将其公开给您的组件) .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM