zoukankan      html  css  js  c++  java
  • vue组件模板及组件间的引用

    1. vue组件都是由这三部分组成

    <template>
      <div>
    
      </div>
    </template>
    
    
    <script>
      export default{}
    </script>
    
    
    <style>
    
    </style>

    2. 组件间的引用分3步走,假设现在有两个组件 App.vue,和 Add.vue,现在要把Add.vue组件引入到App.vue组件中

    App.vue

    <template>
        // 第3步
        <Add/>
    </template>
    
    
    <script>
         // 第1步
        import Add from './components/Add.vue'
        // 第2步
        components: {
          Add
        }
      }
    </script>
    
    
    <style>
    
    </style>

    3. 组件间数据的传递

    假将要将App.vue组件中的数据传递到Ad.vue组件中

    App.vue

    <template>
        // 第3步
        // 传递数据,注意冒号
        <Add :comments="comments"/>
    </template>
    
    
    <script>
         // 第1步
        import Add from './components/Add.vue'
        // 第2步
        components: {
          Add
        },
        // App组件中初始化的数据
         data(){
          return {
            comments: [{
              name: 'Bob',
              content: 'Vue 还不错'
            }, {
              name: 'Cat',
              content: 'Vue so Easy'
            }, {
              name: 'BZ',
              content: 'Vue so so'
            }
            ]
          }
        }
      }
    </script>
    
    
    <style>
    
    </style> 

    Add.vue

    <script>
        export default{
          // 声明接收comments数据
          props: ['comments']
    
        }
    </script>
  • 相关阅读:
    git分支
    git使用
    多人协作
    python初心记录二
    python初心记录一
    Javascript 概念类知识
    想成为前端工程师?希望读完这篇文章能对你有所帮助。
    Egret note
    cocos2d-js 连连看
    PS置入图片之后保留选区方便C图
  • 原文地址:https://www.cnblogs.com/z-qinfeng/p/12383782.html
Copyright © 2011-2022 走看看