• vue实现部分页面导入底部 vue配置公用头部、底部,可控制显示隐藏


    vue实现部分页面导入底部 vue配置公用头部、底部,可控制显示隐藏

    在app.vue文件里引入公共的header 和 footer

    header 和 footer 默认显示,例如某个页面不需要显示header

    可以使用 this.$emit('header',false); 来控制header不显示

    例如:test页面不需要显示header,在页面被创建的时候广播(this.$emit)告诉上级不显示header,

    并且在当前页面写自己的header代码,就可以了

    app.vue

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    <template>
      <div id="app">
        <app-header v-if="header_show"></app-header>
        <router-view v-on:header="header" v-on:footer="footer"></router-view>
        <app-footer v-if="footer_show"></app-footer>
      </div>
    </template>
     
    <script>
    import Header from './components/header'
    import Footer from './components/footer'
    export default {
      name: 'App',
      data(){
          return {
              header_show:true,
              footer_show:true,
          }
      },
      components: {
            'app-header':Header,
            'app-footer':Footer,
      },
      methods:{
          //是否显示头部
          header:function (bool) {
            this.header_show = bool;
          },
          //是否显示底部
          footer:function (bool) {
              this.footer_show = bool;
          }
      }
    }
    </script>

    test.vue

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <template>
        <div>
            test
        </div>
    </template>
     
    <script>
        export default {
            name: 'test',
            components:{
            },
            data () {
                return {
                 
                }
            },
            created:function () {
                this.$emit('header'false);
            }
        }
    </script>

    header.vue

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <template>
        <div class="header">
            head
        </div>
    </template>
     
    <script>
        export default {
            name: 'app-header',
            data () {
                return {
                }
            },
            methods:{
            },
            created(){
            }
        }
    </script>

    footer.vue

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <template>
        <div class="wrap" id="app-footer">
            footer
        </div>
    </template>
     
    <script>
        export default {
            name: 'app-footer',
            data () {
                return {
                }
            }
        }
    </script>
  • 相关阅读:
    操纵持久化对象
    面阵和线扫工业相机选型
    线扫描镜头简介及选型
    Halcon的anisotropic_diffusion()函数,用于对图像进行各向异性散射增强处理
    VB、C#等高级语言与三菱PLC(Q系列、L系列、FX系列、A系列)串口、以太网通讯的DLL及源代码
    Halcon学习笔记之支持向量机
    C#中使用byte[]数据,生成Bitmap(256色 灰度 BMP位图)源代码
    Halcon学习SVM
    利用MLP(多层感知器)创建一个新的OCR分级器
    Halcon中OCR的实现及关键函数解析
  • 原文地址:https://www.cnblogs.com/lgx5/p/10786102.html
Copyright © 2020-2023  润新知