vue簡單的小demo


app.vue

<template>
  <div id="app">
    <v-header v-if="showHeader"></v-header>
    <router-view  v-on:header='header' v-on:footer='footer'/>
    <v-footer v-if="showFooter"></v-footer>
  </div>
</template>

<script>
import header from './components/header.vue'
import footer from './components/footer.vue'
export default {
  name: 'App',
  data(){
    return{
      showHeader:true,
      showFooter:true,
    }
  },
  components:{
    'v-header':header,
    'v-footer':footer,
  },
  methods:{
    //是否顯示頭部
    header:function(bool){
      this.showHeader = bool;
    },
    //是否顯示底部
    footer:function(bool){
      this.showFooter = bool;
    }
  }
}
</script>

<style lang='scss'>
body,html{
  margin:0;
  height:100%;
}
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  height:100%;
}
</style>

header.vue

<template>
    <div>
        我是公共header
    </div>
</template>
<style scoped>
div{
    height:80px;
    line-height:80px;
    background:blue;
    color:#fff;
}
</style>

footer.vue

<template>
    <div>我是公共footer</div>
</template>
<style scoped>
div{
    height:80px;
    line-height:80px;
    background:blue;
    color:#fff;
}
</style>

main.vue

<template>
    <div class="main">
        <div>我是主頁面</div>
        <router-link to="/index">點擊跳轉到首頁</router-link>
    </div>
</template>
<script>
export default {
    data(){
        return{

        }
    },
    created:function(){
        this.$emit('header',false);
        this.$emit('footer',false);
    }
}
</script>
<style scoped lang='less'>
div.main{
    height:100vh;
    background-color: #6714ee; 
    color:#fff;
    div{
        padding-top:20vh;
        font-size:40px;
        margin-bottom:20px;
    }
    a{
        color:red;
    }
    a:hover{
        text-decoration: underline;
        color:#fff;
    }
}
</style>

index.vue

<template>
    <div class="index">
        <div>我是首頁</div>
        <router-link to="/">跳轉到主頁面</router-link>
    </div>
</template>
<script>
export default {
    data(){
        return{

        }
    },
    created:function(){
        this.$emit('header',true);
        this.$emit('footer',true);
    }
}
</script>
<style scoped lang='less'>
    .index{
        height:calc(100vh - 160px);
        background:yellow;
        color:tomato;
        font-size:40px;
        div{
            padding-top:20vh;
        }
        a{
            color:turquoise;
            font-size:20px;
        }
    }
</style>

               

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM