Vue2.0 使用组件

Vue2.0.png

src目录结构

image.png

在components中编辑组件apple.vue:

<template>
  <div id="apple">
      <h1>{{msg}}</h1>
  </div>
</template>

<script>
export default {
  name: 'apple',
  data () {
    return {
      msg:' apple'
    }
  }
}
</script>

<style>
</style>

在App.vue中注册并使用组件

<template>
  <div id="app">
    ![](./assets/logo.png)
    <div>
      do someting here
    </div>
    <!-- 使用组件 -->
    <Apple></Apple> 
  </div>
</template>

<script>
// 导入组件
import Apple from './components/apple'
export default {
  name: 'app',
  // 注册组件,:Apple为import时取的名称,Apple:在使用组件时<Apple></Apple>,此处不分大小写
  components:{Apple:Apple}
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,269评论 25 708
  • 1.今天二刷了《会计书》前面4章,边看边编制报表,对资产负债表和利润表有了更清晰的了解和认识,越看越对财务报表有感...
    半颗糖依然很甜阅读 199评论 0 0
  • 如今回顾写作过程,我发现自己始终在思考一个问题:站在人生的岔路口,人究竟该怎么做?我希望读者掩卷时喃喃自语:我从未...
    强强爱做梦阅读 1,694评论 1 23
  • 我们庆祝生,痛惜死,害怕生病,对衰老无可奈何。 我一直觉得上帝给每个人分配了苦与甜,可能没那么等额,但是要你自己经...
    板栗Keira阅读 306评论 0 1
  • 高适《蓟中作》原诗、注释、翻译、赏析 【原文】:蓟中作高 适策马自沙漠,长驱登塞垣。边城何萧条,白日黄云昏。一到征...
    xcy无名阅读 264评论 0 0