zoukankan      html  css  js  c++  java
  • vue 引用其他组件

    1、在components 目录下新建Test.vue 文件

    <template>
      <div class="test">
        <h1>{{ msg }}</h1>
        <router-link to="/login">跳转到详情页</router-link>
      </div>
    </template>
    
    <script>
    export default {
      name: 'test',
      data () {
        return {
          msg: 'this.test uve'
        }
      }
    }
    </script>
    
    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
    h1, h2 {
      font-weight: normal;
    }
    
    ul {
      list-style-type: none;
      padding: 0;
    }
    
    li {
      display: inline-block;
      margin: 0 10px;
    }
    
    a {
      color: #42b983;
    }
    </style>
    

      

    2、在Hell.vue里添加代码引用Test.vue

    <template>
      <div class="hello">
    
        <h1>{{ msg }}</h1>
         <!-- 引用的组件标签 和下边 import 的名称保持一致 -->
        <test></test>
      </div>
    
    </template>
    
    <script>
    // 引用Test.vue 命名为test
    import test from './Test'
    export default {
      name: 'hello',
      // 引用组件
      components:{
        test
      },
      data () {
        return {
          msg: 'Welcome to Your Vue.js App'
        }
      }
    }
    </script>
    
    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
      h1, h2 {
        font-weight: normal;
      }
    
      ul {
        list-style-type: none;
        padding: 0;
      }
    
      li {
        display: inline-block;
        margin: 0 10px;
      }
    
      a {
        color: #42b983;
      }
    </style>
    

    运行结果:  

  • 相关阅读:
    团队与领导力健康检查 | 体检表
    如何改变组织文化
    如何在各种文化背景下成功敏捷
    OKR痛点与误区 | 敏捷家分享007
    Scrum培训感想
    如何讲好故事
    Lc70_爬楼梯
    Lc641_设计循环双端队列
    Lc32_最长有效括号
    Lc239_滑动窗口最大值
  • 原文地址:https://www.cnblogs.com/gouge/p/7281136.html
Copyright © 2011-2022 走看看