<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="vue.js"></script>
</head>
<body>
<div id="app">
<father></father>
</div>
<script>
//1
// Vue.component(
// 'my-component',{
// template:`
// <div>
// <slot>
// 只有在没有要分发的内容时才会显示。
// </slot>
// <h2>我是子组件的标题</h2>
// </div>`
// }
// )
// var app = new Vue({
// data:'',
// components:{
// 'father':{
// template:`<div>
// <h1>我是父组件的标题</h1>
// <my-component>
// <p>这是一些初始内容</p>
// <p>这是更多的初始内容</p>
// </my-component>
// </div> `
// }

// }
// }).$mount('#app');
//自组建标记中本来不应该写入值,但加入slot后,父组件中在子组件写的标记会写入slot中。如果去掉slot则不会显示初始内容和更多内容

//2具名插槽
// Vue.component(
// 'my-component',{
// template:`
// <div class="container">
// <header>
// <slot name="header"></slot>
// </header>
// <main>
// <slot></slot>
// </main>
// <footer>
// <slot name="footer"></slot>
// </footer>
// </div>`
// }
// )

// var app = new Vue({
// data:'',
// components:{
// 'father':{
// template:
// `<my-component>
// <h1 slot="header">这里可能是一个页面标题</h1>
// <p>主要内容的一个段落。</p>
// <p>另一个主要段落。</p>
// <p slot="footer">这里有一些联系信息</p>
// </my-component>`
// }

// }
// }).$mount('#app');

//3作用域插槽
Vue.component(
'my-component',{
template:`
<div class="child">
<slot text="hello from child" css="abc"></slot><div>您好</div>
</div>`
}
)

var app = new Vue({
data:'',
components:{
'father':{
template:
`<div class="parent">
<my-component>
<template slot-scope="props">
<span>hello from parent</span>
<span>{{ props.text }}{{ props.css }}</span>
</template>
</my-component>
</div>`
}

}
}).$mount('#app');

//在父级中,具有特殊特性 slot-scope 的 <template> 元素必须存在,表示它是作用域插槽的模板。slot-scope 的值将被用作一个临时变量名,此变量接收从子组件传递过来的 prop 对象。相当于从子组件传递数据给父组件。
</script>
</body>
</html>

vue2.0使用slot插槽分发内容的更多相关文章

  1. vue组件-使用插槽分发内容(slot)

    slot--使用插槽分发内容(位置.槽口:作用: 占个位置) 官网API: https://cn.vuejs.org/v2/guide/components.html#使用插槽分发内容 使用组件时,有 ...

  2. vue2.0 之 slot 内容分发

    前提:父组件模板的内容在父组件作用域内编译:子组件模板的内容在子组件作用域内编译.被分发的内容会在父作用域内编译. 一.单个插槽 // 子组件模板 child-component <div> ...

  3. Vue结合slot插槽分发父组件内容实现高度复用、更加灵活的dialog组件

    之前写过一篇关于vue实现dialog会话框组件的文章(http://www.cnblogs.com/fozero/p/8546883.html)[http://www.cnblogs.com/foz ...

  4. 使用Vue的slot插槽分发父组件内容实现高度复用、更加灵活的组件

    写在前面 之前写过一篇关于vue实现dialog会话框组件的文章http://www.cnblogs.com/fozero/p/8546883.html, 讲到了如何实现一个vue对话框组件,其中涉及 ...

  5. Vue组件-使用插槽分发内容

    在使用组件时,我们常常要像这样组合它们: <app> <app-header></app-header> <app-footer></app-fo ...

  6. Vuejs-组件-<slot> 标签分发内容

    资料来自:https://cn.vuejs.org/v2/guide/components.html#具名-Slot 在官方文档的基础上,更加细致的讲解代码. <slot> 标签中的任何内 ...

  7. vue使用插槽分发内容slot的用法

    将父组件的内容放到子组件指定的位置叫做内容分发 //在父组件里使用子组件 <son-tmp> <div>我是文字,我需要放到son-tmp组件里面制定的位置</div&g ...

  8. vue 通过插槽分发内容

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. Vue2.0 官方文档学习笔记

    VUE2.0官方文档 基础部分: 1.VUE简介 Vue是一个基于MVVM的框架,其中M代表数据处理层,V代表视图层即我们在Vue组件中的html部分,VM即M和V的结合层,处理M层相应的逻辑数据,在 ...

随机推荐

  1. UE4 多人FPS VR游戏制作笔记

    1, 2,服务器游戏流程 服务器负责驱动游戏流程.服务器的职责是在游戏开始/结束以及 actor 复制更新等情况下通知客户端转移到新地图. 主要架构部分 大多在本文的讨论范围之外,但我们可以在遇到特定 ...

  2. line-height相关总结

    line-height http://cindylu520.iteye.com/blog/670512 四个boxes containing boxes inline boxes 匿名inline b ...

  3. 用adb录制手机屏幕视频

    adb shell screenrecord命令可以用来录制Android手机视频 screenrecord是一个shell命令,支持Android4.4(API level 19)以上,支持视频格式 ...

  4. JVM GC杂谈之理论入门

    GC杂谈之理论入门 JVM堆布局介绍 ​ JVM堆被划分成两个不同的区域:新生代 ( Young ).老年代 ( Old ).新生代 ( Young ) 又被划分为三个区域:Eden.From Sur ...

  5. zookeeper部署和运行

    环境准备: 操作系统,此处使用windows系统 Java运行环境,JDK1.6以上 下载对应操作系统zookeeper安装包zookeeper-x.x.x.tar.gz,下载地址:http://zo ...

  6. PhpStorm常用的一些快捷键

    Ctrl + G  :  跳到当前打开文件的行,输入格式(行数:列数)Ctrl + E  : 打开最近编辑的文件列表Ctrl + P  : 显示函数的参数信息Ctrl + Q  : 快速打开函数的说明 ...

  7. vue 入门第一课

    windows安装git 安装淘宝镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org 全局安装vue cnpm inst ...

  8. SQL中MAX()

    列column_name中的数据可以是数值.字符串或是日期时间数据类型.

  9. c#套料程序设计

    上的套料基本上都没有源码,开放的sdk都没有,这让很多想做套料,但是又成本太高了. 另外,大部分套料都是c++实现的,效率高,本人尝试用c#做一个套料程序,发现效率也不低,当然会比c++差点. 以下是 ...

  10. FormsAuthentication.HashPasswordForStoringInConfigFile 的替代方法

    由于项目中要和php对接,要将一段字符串生成md5(16位)验证码,在英文字符时,没有太大问题,但在遇到中文时,两边字条始终不一致. php是别人的项目,看不到源码,网上一查,估计是这样写的: < ...