App.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <div id="app">
  3. <h3>我是App组件</h3>
  4. <!-- 组件渲染 时 和 html标签的定义 是 一样的 -->
  5. <MyCounter />
  6. <!-- 给MyParent子组件传递数据 -->
  7. <!-- 父组件给子组件传递数据 第1步: 在渲染组件时 给其绑定一个自定义属性。注意属性名字 要遵循html规范:不支持驼峰命名,如果包含多个单词 就使用 短横线分隔 (kebab-case)-->
  8. <!-- <MyParent :d="toP" /> -->
  9. <MyParent :my-data="toP" />
  10. </div>
  11. </template>
  12. <script>
  13. // 1 先将子组件 引入 当前模块中
  14. import MyCounter from './components/MyCounter.vue';
  15. import MyParent from './components/MyParent.vue';
  16. export default {
  17. name: 'App',
  18. // 2 使用下面属性 给 组件 添加/注册 子组件
  19. components: {
  20. // MyCounter: MyCounter
  21. MyCounter,
  22. MyParent,
  23. },
  24. data() {
  25. return {
  26. toP: 'App 给 Parent组件的数据',
  27. };
  28. },
  29. };
  30. </script>
  31. <style>
  32. #app {
  33. font-family: Avenir, Helvetica, Arial, sans-serif;
  34. -webkit-font-smoothing: antialiased;
  35. -moz-osx-font-smoothing: grayscale;
  36. text-align: center;
  37. color: #2c3e50;
  38. margin-top: 60px;
  39. }
  40. </style>