• 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>
  • 相关阅读:
    【JZOJ3852】【NOIP2014八校联考第2场第2试9.28】单词接龙(words)
    【JZOJ3853】【NOIP2014八校联考第2场第2试9.28】帮助Bsny(help)
    【JZOJ3854】【NOIP2014八校联考第2场第2试9.28】分组(group)
    【JZOJ4934】【NOIP2017GDKOI模拟1.12】a
    【JZOJ4935】【NOIP2017GDKOI模拟1.12】b
    【JZOJ4925】【GDOI2017模拟12.18】稻草人
    【JZOJ4930】【NOIP2017提高组模拟12.18】C
    【JZOJ4929】【NOIP2017提高组模拟12.18】B
    如何重新加载Spring Boot上的更改,而无需重新启动服务器?
    什么是JavaConfig及其优点?
  • 原文地址:https://www.cnblogs.com/mingforyou/p/15200926.html
Copyright © 2020-2023  润新知