美文网首页vue
webstorm-vueCli 组件的嵌套

webstorm-vueCli 组件的嵌套

作者: rainbowz | 来源:发表于2019-02-25 22:16 被阅读4次

    1项目截图

    图片.png

    account.vue
    login.vue
    register.vue

    <template>
      <div>
        <h1>这是Account组件</h1>
        <router-link to="/account/login">登录</router-link>
        <router-link to="/account/register">注册</router-link>
    
        <router-view></router-view>
      </div>
    </template>
    
    <script>
    export default {
      name: 'Account'
    }
    </script>
    
    <style scoped>
    
    </style>
    
    
    <template>
        <div>登录</div>
    </template>
    
    <script>
        export default {
            name: "login"
        }
    </script>
    
    <style scoped>
    
    </style>
    
    
    <template>
        <div>注册</div>
    </template>
    
    <script>
        export default {
            name: "login"
        }
    </script>
    
    <style scoped>
    
    </style>
    
    
    2

    index.js
    App.vue
    main.js

    import Vue from 'vue'
    import Router from 'vue-router'
    import account from '@/components/Account'
    import login from '@/components/login'
    import register from '@/components/register'
    import HelloWorld from '@/components/HelloWorld'
    
    Vue.use(Router)
    
    export default new Router({
      routes: [
        {path: '/', name: 'HelloWorld', component: HelloWorld},
       /* /!*{path:'/account',component:account,children:[
            {path:'login',component:login},
    
          ]},*!/
        {path:'/login',component:login},*/
    
        {path:'/account',component:account,children:[
            {path:'login',component:login},
            {path:'register',component:register},
          ]},
      ]
    })
    
    

    app.vue

    <template>
      <div id="app">
        <img src="./assets/logo.png">
        <h3>首页</h3>
        <router-link to="/account">account</router-link>
        <router-view></router-view>
      </div>
    </template>
    

    main.js

    // The Vue build version to load with the `import` command
    // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
    import Vue from 'vue'
    import App from './App'
    import router from './router'
    
    Vue.config.productionTip = false
    
    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      router,
      components: { App },
      template: '<App/>'
    })
    
    
    图片.png 图片.png

    相关文章

      网友评论

        本文标题:webstorm-vueCli 组件的嵌套

        本文链接:https://www.haomeiwen.com/subject/wybnyqtx.html