zoukankan      html  css  js  c++  java
  • Vue工程添加组件调用

    App.vue

    <template>
      <div id="nav">
        <router-link to="/">Home</router-link> |
        <router-link to="/about">About</router-link> |
        <router-link to="/test1">Test1</router-link>
      </div>
      <router-view/>
    </template>
    
    <style>
    #app {
      font-family: Avenir, Helvetica, Arial, sans-serif;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
      text-align: center;
      color: #2c3e50;
    }
    
    #nav {
      padding: 10px;
      background-color: lightskyblue;
    }
    
    #nav a {
      font-weight: bold;
      color: #2c3e50;
    }
    
    #nav a.router-link-exact-active {
      color:orangered;
    }
    </style>

    index.js

    import { createRouter, createWebHashHistory } from 'vue-router'
    import Home from '../views/Home.vue'
    
    const routes = [
      {
        path: '/',
        name: 'Home',
        component: Home
      },
      {
        path: '/about',
        name: 'About',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
      },
      {
        path: '/test1',
        name: 'Test1',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/Test1.vue')
      }
    ]
    
    const router = createRouter({
      history: createWebHashHistory(),
      routes
    })
    
    export default router

    Test1.vue

    <template>
      <div class="test1">
        <h1>This is a test1 page</h1>
        <Test1Top msg="Welcome to Test1Top"/>
        <Test1Center msg="Welcome to Test1Center"/>
        <Test1Bottom msg="Welcome to Test1Bottom"/>
      </div>
    </template>
    
    <script>
    // @ is an alias to /src
    import Test1Top from '@/components/Test1Top.vue';
    import Test1Center from '@/components/Test1Center.vue';
    import Test1Bottom from '@/components/Test1Bottom.vue';
    
    export default {
      name: 'Test1',
      data(){
        return{
    
        }
      },
      components: {
        Test1Top,Test1Center,Test1Bottom
      }
    }
    </script>

    Test1Top.vue

    <template>
      <div>
        Test1Top
        <input type="text" placeholder="请输入">
      </div>
    </template>
    
    <script>
    export default {
      name: 'Test1Top'
    }
    </script>
    
    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
    
    </style>

    Test1Center.vue

    <template>
    <div>
      Test1Center
      <div>
         <table border="1px;" width="80%;">
           <tr>
             <th>1</th>
             <th>2</th>
             <th>3</th>
           </tr>
           <tr>
             <td>a</td>
             <td>b</td>
             <td>c</td>
           </tr>
         </table>
      </div>
    </div>
    </template>
    
    <script>
    export default {
      name: 'Test1Center'
    }
    </script>
    
    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
    
    </style>

    Test1Bottom.vue

    <template>
      <div>
        Test1Bottom
        <span>共1条</span>
      </div>
    
    </template>
    
    <script>
    export default {
      name: 'Test1Bottom'
    }
    </script>
    
    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
    
    </style>
  • 相关阅读:
    AndroidApplication Fundamentals(Android应用基础)
    当汇错款时该怎么办?
    VS2005控制台程序修改nb0文件
    nand flash 扇区的管理以及初始化
    Androidz之Activity概要学习
    Android开发者必备的42个链接
    Android Activity形象描述
    一个前端妹子的悲欢编程之路
    提高工作效率的几个小技巧
    前端几个常用简单的开发手册拿走不谢
  • 原文地址:https://www.cnblogs.com/mingforyou/p/15200926.html
Copyright © 2011-2022 走看看