vue2.0使用slot插槽分发内容
<!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插槽分发内容的更多相关文章
- vue组件-使用插槽分发内容(slot)
slot--使用插槽分发内容(位置.槽口:作用: 占个位置) 官网API: https://cn.vuejs.org/v2/guide/components.html#使用插槽分发内容 使用组件时,有 ...
- vue2.0 之 slot 内容分发
前提:父组件模板的内容在父组件作用域内编译:子组件模板的内容在子组件作用域内编译.被分发的内容会在父作用域内编译. 一.单个插槽 // 子组件模板 child-component <div> ...
- Vue结合slot插槽分发父组件内容实现高度复用、更加灵活的dialog组件
之前写过一篇关于vue实现dialog会话框组件的文章(http://www.cnblogs.com/fozero/p/8546883.html)[http://www.cnblogs.com/foz ...
- 使用Vue的slot插槽分发父组件内容实现高度复用、更加灵活的组件
写在前面 之前写过一篇关于vue实现dialog会话框组件的文章http://www.cnblogs.com/fozero/p/8546883.html, 讲到了如何实现一个vue对话框组件,其中涉及 ...
- Vue组件-使用插槽分发内容
在使用组件时,我们常常要像这样组合它们: <app> <app-header></app-header> <app-footer></app-fo ...
- Vuejs-组件-<slot> 标签分发内容
资料来自:https://cn.vuejs.org/v2/guide/components.html#具名-Slot 在官方文档的基础上,更加细致的讲解代码. <slot> 标签中的任何内 ...
- vue使用插槽分发内容slot的用法
将父组件的内容放到子组件指定的位置叫做内容分发 //在父组件里使用子组件 <son-tmp> <div>我是文字,我需要放到son-tmp组件里面制定的位置</div&g ...
- vue 通过插槽分发内容
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Vue2.0 官方文档学习笔记
VUE2.0官方文档 基础部分: 1.VUE简介 Vue是一个基于MVVM的框架,其中M代表数据处理层,V代表视图层即我们在Vue组件中的html部分,VM即M和V的结合层,处理M层相应的逻辑数据,在 ...
随机推荐
- LINUX服务器--所有用户登陆操作命令审计
Linux用户操作记录我们都可以通过命令history来查看历史记录,但是如果因为某人误操作了删除了重要的数据,那么Linux history命令就基本上不会有太大的作用了.我们怎么来查看Linux用 ...
- SLAM入门之视觉里程计(6):相机标定 张正友经典标定法详解
想要从二维图像中获取到场景的三维信息,相机的内参数是必须的,在SLAM中,相机通常是提前标定好的.张正友于1998年在论文:"A Flexible New Technique fro Cam ...
- koala 编译scss不支持中文(包括中文注释),解决方案如下
进入Koala安装目录,例如:C:\Program Files (x86)\Koala\rubygems\gems\sass-3.4.9\lib\sass 找到engine.rb文件,在该文件中找到最 ...
- POJ 1502 MPI Maelstrom(模板题——Floyd算法)
题目: BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distri ...
- VUE之随笔小总结1
VUE 它是一个构建用户界面的JavaScript框架vue指令: 是带有v-前缀的特殊属性,通过属性来操作元素 v-text:在元素当中插入文本 eg:属性值会覆盖自己插入的值 //插入一段文本&l ...
- hbase伪分布式安装(单节点安装)
hbase伪分布式安装(单节点安装) http://hbase.apache.org/book.html#quickstart 1. 前提配置好java,环境java变量 上传jdk ...
- 利用PHPExcel导出Excel并设置Excel格式以及数据源
浏览:23969 发布日期:2013/07/24 分类:技术分享 代码有点长,读起来有点累.先来个截图 导出的Excel太宽了,所以将后面的列宽重新调整了再截的图 功能包括: 1.设置单元格格式,包括 ...
- [SinGuLaRiTy] NOIP模拟题 by liu_runda
[SinGuLaRiTy-1046] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 题目名称 兔子 被子 蚊子 源程序文件名 rabbit. ...
- MyEclipse或Eclipse导出JavaDoc中文乱码问题解决
- Lucene.net(4.8.0) 学习问题记录四: IndexWriter 索引的优化以及思考
前言:目前自己在做使用Lucene.net和PanGu分词实现全文检索的工作,不过自己是把别人做好的项目进行迁移.因为项目整体要迁移到ASP.NET Core 2.0版本,而Lucene使用的版本是3 ...