• header.vue 调用变量,别的组件导入引用,组件方法事例实例


    <template>
    <div id="header">
    <!-- 调用变量 -->
    <h1>{{ msg }}</h1>

    <!-- 3:调用组件的方法 -->
    <p>{{ webInfo() }}</p>
    <p>{{ webArea() }}</p>
    <!-- 2:显示用户信息组件-->
    <vProduct></vProduct>
    <!--vProduct如果放在<div id="header"外,会提示: 组件模板应该只包含一个根元素。 -->
    </div>

    </template>

    <script>
    // 1:引导同目录下./userInfo.vue组件 并命名为vUserInfo,其中./表示在当前目录
    import vUserInfo from './userInfo.vue'
    import vProduct from './product.vue'
    export default {
    data () {
    return {
    msg: '我的主页 home.vue',
    webUrl: 'http://www.sqfcw.net',
    address: '宿迁市宿城我'
    }
    },
    components: {
    // 2:添加子组件vUserInfo,多个组件之间可以用,相隔开,此组件来源于上边import from
    vUserInfo, vProduct
    },
    methods: {
    // 3:添加组件的方法
    webInfo: function () {
    return '站点信息待完善' + this.webUrl
    },
    webArea: function () {
    return '所在地区:' + this.address
    }
    }
    }
    </script>

    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
    #header {
    background: green;
    }
    #header p {
    background: gold;
    color: red;
    }
    #header ul {
    height: 35px;
    background: orange;
    }
    #header ul li {
    padding: 0 10px;
    height: 35px;
    line-height: 35px;
    float: left;
    /* float: left; */
    }
    </style>
    做产品的程序,才是好的程序员!
  • 相关阅读:
    洛谷 P1919 【模板】A*B Problem升级版(FFT快速傅里叶)
    Codeforces Goodbye 2018
    ubuntu 百度云
    【UOJ 351】新年的叶子
    【SDOI2008】仪仗队
    NOI 2002 贪吃的九头龙
    最大获利
    codeforces 814E An unavoidable detour for home
    codeforces 814D An overnight dance in discotheque
    bzoj3191 [JLOI2013]卡牌游戏
  • 原文地址:https://www.cnblogs.com/asplover/p/10985027.html
Copyright © 2020-2023  润新知