美文网首页
vue-ts中的@Component

vue-ts中的@Component

作者: 前端老邹_伯通 | 来源:发表于2020-03-17 18:54 被阅读0次

有同学看【手把手教你使用TS+Vue打造黑马便签应用】时问到 vue-ts中的@Component 是什么意思?简单回复如下,请诸位看官大爷【笑纳斧正】:

  • Component 是 vue-class-component 中的装饰器修饰组件,用来为组件类添加各种“装饰属性”,懂 Java或C#的同学应该了解,这就是所谓的 注解

  • 注解 :是一种依赖注入的方法,为了降低代码的耦合度。
    简单的说,就是 框架 负责为类额外添加一些成员和功能,而 开发者 负责通过 注解 的方式 将数据传给 框架,框架收到 注解 传入的数据后,可以用在 类上

  • 我们看下面段代码:通过 @Component 为 名为 App的类 传了一个对象,而对象中,就包含了 很多属性,比如:components

<template>
  <div id="app">
    <MenuBar/>
    <ItemList/>
    <MemoEditor v-if="$store.state.isShow"/>
    <test/>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import MenuBar from './components/MenuBar.vue'
import ItemList from './components/ItemList.vue'
import MemoEditor from './components/MemoEditor.vue'
import test from './components/test.vue'

@Component({
  components: {
    MenuBar,
    ItemList,
    MemoEditor,
    test
  },
})
export default class App extends Vue {
  
}
</script>
  • 看图再说话


    明白了吗?这就是所谓“注解”

相关文章

网友评论

      本文标题:vue-ts中的@Component

      本文链接:https://www.haomeiwen.com/subject/aqlxyhtx.html