在vue中使用插槽 slot
<div id='root'>
<child content = '<p>Dell</p>'></child>
</div> <script>
Vue.component('child',{
props:['content'],
template:`
<div>
<p>hello</p>
<div v-html='this.content'></div>
</div>
`
})
var vm = new Vue({
el:'#root'
})
</script>
<div id='root'>
<child>
<h1>dell</h1>
</child>
</div> <script>
Vue.component('child',{
template:`
<div>
<p>hello</p>
<slot></slot>
</div>
`
})
var vm = new Vue({
el:'#root'
})
</script>
像这样,父组件里面直接写dom元素,通过slot引用,在子组件插入点内容,叫做插槽
Vue.component('child',{
template:`
<div>
<p>hello</p>
<slot>默认内容</slot>
</div>
`
})
<div id='root'>
<body-content>
<div class="header">header</div>
<div class="footer">footer</div>
</body-content>
</div> <script>
Vue.component('body-content',{
template:`
<div>
<slot></slot>
<div>content</div>
<slot></slot>
</div>
`
})
var vm = new Vue({
el:'#root'
})
</script>
<div id='root'>
<body-content>
<div class="header" slot='header'>header</div>
<div class="footer" slot='footer'>footer</div>
</body-content>
</div> <script>
Vue.component('body-content',{
template:`
<div>
<slot name='header'></slot>
<div>content</div>
<slot name='footer'></slot>
</div>
`
})
var vm = new Vue({
el:'#root'
})
</script>
在vue中使用插槽 slot的更多相关文章
- vue中的插槽slot
插槽(slot):是组件的一块HTML模板,父组件决定这块模板显不显示以及怎么显示. 位置由子组件自身决定(slot现在组件template的什么位置,父组件传过来的模板将来就显示在什么位置) 匿名插 ...
- vue中的插槽slot理解
本篇文章参考赛冷思的个人博客 1.函数默认传参 在我们写js函数我们的可能会给他们一个默认的参数,写法是 function show(age,name){ var age = age || 20; v ...
- Vue中的插槽---slot
一:什么是插槽? 插槽(Slot)是Vue提出来的一个概念,正如名字一样,插槽用于决定将所携带的内容,插入到指定的某个位置,从而使模板分块,具有模块化的特质和更大的重用性. 插槽显不显示.怎样显示是由 ...
- vue中的插槽(slot)
vue中的插槽,指的是子组件中提供给父组件使用的一个占位符,用<slot></slot>标签表示,父组件可以在这个占位符中填充任何模板代码,比如HTML.组件等,填充的内容会替 ...
- vue中具名插槽的使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 详解Vue中的插槽
作者: 小土豆 博客园:https://www.cnblogs.com/HouJiao/ 掘金:https://juejin.im/user/2436173500265335 什么是插槽 在日常的项目 ...
- 第八十九篇:Vue 重学插槽slot
好家伙, 1.什么是插槽? 插槽是vue为组件的封装者提供的能力.允许开发者在封装组件时, 把不确定的,希望由用户指定的部分定义为插槽 我们依然可以把它理解为一个占位符 1.1.插槽的基本用法 试 ...
- vue中$refs、$slot、$nextTick相关的语法
Vue 实例还暴露了一些有用的实例属性与方法.它们都有前缀 $,以便与用户定义的属性区分开来 1.$data和$el var data = { a: 1 } var vm = new Vue({ el ...
- vue中的插槽
匿名插槽 // comp1 <div> <slot></slot> </div> // parent <comp>hello</com ...
随机推荐
- python3 logging笔记
#coding:utf-8import logging logger = logging.getLogger("simple_example")#可以说是日志信息的名字吧,可以随便 ...
- HikariPool连接池的使用
HikariDataSource datasource= new HikariDataSource( xxxx ); Connection cn = datasource.getConnection( ...
- 数据结构---Java---ArrayList
public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess ...
- [inner] bug
这样正确 command: ["sh", "-c", "mysql -h${DC_DB_HOST} -uroot -p${MYSQL_ROOT_PAS ...
- WebGL 踩坑系列-2
需求:绘制斑点在球面上走过的路径 思路:要绘制斑点在球面上走过的路径,首先要记录上一时刻和当前时刻该斑点所在球面的位置,并且实时更新当前时刻的斑点位置和上一时刻的斑点位置. 为了方便,上一时刻斑点所在 ...
- POJ 1236——Network of Schools——————【加边形成强连通图】
Network of Schools Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u ...
- UVA 10462 —— Is There A Second Way Left?——————【最小生成树、kruskal、重边】
Nasa, being the most talented programmer of his time, can’t think things to be so simple. Recently a ...
- 远程登陆服务器(window系统)
1,打开命令输入框: 快捷键:win+R 2.输入命令:mstsc 3.输入你的IP地址和用户名(一般为administrator) 4.输入密码
- [Java][Servlet] Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]
Background: Servlet version 3.1(3.0之后就有了@WebServlet注解) Error 严重: Failed to destroy end point associa ...
- mybatis SqlSession事务
mybatis版本:3.4.6. mybatis默认的SqlSessionFactory是DefaultSqlSessionFactory,它openSession()的源码是: public Sql ...