zoukankan      html  css  js  c++  java
  • vuebase----3.slot插槽

    1.不具名slot;

    2.具名slot;

    3.父组件模板的东西在父级作用域内编译,子组件模板的所有东西在子级作用域内编译;

    4.编译作用域

    5.作用域插槽(数据传递)

    6.数据可以动态的改变

    ------------------------------------------------------------App.vue-------------------------------------------------------------------------

    <template>
    <div id="app">
    <img src="./assets/logo.png">
    <!-- <HelloWorld/> -->
    <Parent />
    <!-- <Music/> -->
    <slotDemo>
    <!-- <div>hello插槽</div>
    <template slot="v1">
    <div class="v1">{{slotParentmsg}}</div>
    </template>
    <template slot="v2">
    <div class="v1">v2内容</div>
    </template> -->
    <div slot-scope="slotparents"><h2>{{slotparents.msgs}}</h2></div>
    </slotDemo>
    </div>
    </template>

    <script>
    /* import HelloWorld from './components/HelloWorld' */
    import Parent from './components/parent'
    import Music from './components/music'
    import slotDemo from './components/slotDemo'

    export default {
    name: 'App',
    components: {
    Parent,
    Music,
    slotDemo
    },
    data(){
    return{
    slotParentmsg:"插槽的动态内容"
    }
    },
    methods:{

    }
    }
    </script>

    <style>
    #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    margin-top: 60px;
    }
    </style>

    ----------slotDemo.vue---------

    <template>
    <div>
    <!-- <slot name="v1"></slot>
    <slot name="v2">默认信息</slot> -->
    <slot :msgs="msg"></slot>
    </div>
    </template>

    <script>
    export default {
    name: "slotDemo",
    data() {
    return {
    msg:"子插槽的数据动态改变"
    }
    }
    }
    </script>

    <style lang="css" scoped>
    </style>

    ------------------------parent.vue-------------------------------

    <template>
    <div class="parent">
    <slotDemo>
    <template slot-scope="slotparents">
    <h1>1111----{{slotparents.msgs}}----1111</h1>
    </template>
    </slotDemo>
    父组件:
    <p>{{sendParentinfo}}</p>
    小明明称呼:
    <Child title="父组件的数据" nick="小宝贝" friend="" parentss="小宝贝爸爸" :age="age" @sendParentinfo="sendParentinfos" />
    <p>{{gemsgInfo}}</p>
    </div>
    </template>

    <script>
    import slotDemo from './slotDemo'
    import Child from './child'
    export default {
    name: "parent",
    components: {
    Child,
    slotDemo
    },
    data() {
    return {
    sendParentinfo:"",
    age:1000
    }
    },
    computed:{
    gemsgInfo(){
    return this.$root.msg
    }
    },
    methods: {
    sendParentinfos(data) {
    this.sendParentinfo=data
    }
    }
    }
    </script>
    <style lang="css" scoped>
    </style>

  • 相关阅读:
    记忆碎片:我的2007
    查看 Oracle 是用spfile 启动还是 pfile 启动
    Oracle 10g OCP 042 题库 71120 题 共168题
    Oracle OLAP 与 OLTP 介绍
    Oracle Data Guard Switchover 切换
    Linux 终端访问 FTP 及 上传下载 文件
    多表连接的三种方式详解 HASH JOIN MERGE JOIN NESTED LOOP
    Oracle 表连接方式(内连接/外连接/自连接) 详解
    Oracle 表连接方式(内连接/外连接/自连接) 详解
    查看 Oracle 是用spfile 启动还是 pfile 启动
  • 原文地址:https://www.cnblogs.com/xiao-peng-ji/p/11329863.html
Copyright © 2011-2022 走看看