1_02 Vue Slot
slot 插槽
- 插槽内容
const component ={
template: `
<div>
<slot></slot>
</div>
`
}
new Vue ({
components: {
com: components
},
el: '#app',
template: `
<div>
<com>
this is contnent.
</com>
</div>
`
})
- 具名插槽
const component = {
template: `
<div>
<slot name="header"></slot>
<slot name="main"></slot>
<slot name="footer"></slot>
</div>
`
}
new Vue({
components: {
component
},
el: '#app',
template: `
<div>
<com>
<template name="header">header</template>
<template name="main">main</template>
<template name="footer">footer</template>
</com>
</div>
`
})
根据是否有插槽内容,来判断显示内容。vue提供$slots属性,每个具名插槽的name都是$slots的属性,但是有的直接使用<slot></slot>没有具名,则用$slots.default表示,如下例子:
const component = {
template: `
<div :style="style">
<slot name="header"></slot>
<slot v-if="$slots.default"></slot>
<template v-if="!$slots.default">
there are no data.
</template>
<slot name="footer" v-if="$slots.footer"></slot>
<template v-if="!$slots.footer">
if footer is not exsit, show the content.
</template>
</div>
`,
data () {
return {
style: {
width: '200px',
height: '200px',
border: '1px solid #aaa',
}
}
}
}
new Vue({
components: {
ComOne: component
},
el: '#app',
template: `
<div>
<ComOne>
<template slot="header">header</template>
</ComOne>
</div>
`
});
slot-scope的用法
将子组件的属性通过 slot-scope 传递给父组件中对应子组件插槽内容中。
const component = {
template: `
<div :style="style">
<slot :value="value"></slot>
</div>
`,
props: {
value: {
default: 'liangcheng',
type: String
},
},
data () {
return {
style: {
width: '200px',
height: '200px',
border: '1px solid #aaa',
}
}
}
}
new Vue({
components: {
ComOne: component
},
el: '#app',
template: `
<div>
<ComOne value="lc">
<template slot-scope="props">{{ props.value }}</template>
</ComOne>
</div>
`
});
1_02 Vue Slot的更多相关文章
- vue自学入门-4(vue slot)
vue自学入门-1(Windows下搭建vue环境) vue自学入门-2(vue创建项目) vue自学入门-3(vue第一个例子) vue自学入门-4(vue slot) vue自学入门-5(vuex ...
- vue slot nested bug
vue slot nested bug slot name bug Error <slot name="global-system-guide-slot"></s ...
- Vue slot 插槽用法:自定义列表组件
Vue 框架的插槽(slot)功能相对于常用的 v-for, v-if 等指令使用频率少得多,但在实现可复用的自定义组件时十分有用.例如,如果经常使用前端组件库的话,就会经常看到类似的用法: < ...
- Vue slot插槽
插槽用于内容分发,存在于子组件之中. 插槽作用域 父级组件作用域为父级,子级组件作用域为子级,在哪定义的作用域就在哪. 子组件之间的内容是在父级作用域的,无法直接访问子组件里面的数据. 插槽元素 &l ...
- Vue slot插槽内容分发
slot插槽使用 使用场景,一般父组件中又一大段模板内容需要运用到子组件上.或者更加复杂的,子组件需要运用到父组件大段模板内容,而子组件却不知道挂载的内容是什么.挂载点的内容是由父组件来决定的. Sl ...
- vue slot 复用
话不投机半句多,直接上代码 有3步 第一步:创建渲染slot的组件 重要 第二步:为slot添加父组件数据(props) 重要 第三步:使用 第一步:创建渲染slot的组件 首选创建一个单文件组价,由 ...
- vue slot
一直觉得vue的slot比较申请,而且比较深奥,总有点不想用的感觉,事实上,在一定程度上,也真的可以完全避开slot就能把一个项目完全搭建完成. 但是随着用的次数越来越多,看到的内容也越来越多的情况, ...
- vue slot插槽的使用方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Vue slot简单理解
情形一: 子组件定义了具名的slot,父组件使用具名的slot,slot显示顺序为子组件定义slot的顺序 子组件: Vue.component('child',{ template:`<div ...
随机推荐
- laravel5.4中验证与错误提示设置
1.对于交互提交数据,验证如: #验证 $this->validate(\request(),[ 'title' => 'required|string|min:3|max:20', 'c ...
- Windows 8(64位)如何搭建 Android 开发环境与真机测试(转)
可以参考http://wenku.baidu.com/link?url=ghU6IFS1WJXLFKfM_0efv9YQEnMDBrdi9CXwirSs5IOLLeUfdIOh8OOVv0DX89Lt ...
- The last packet successfully received from the server was 20,519 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
本地升级了下MySQL的版本,从5.6升为5.7,数据文件直接拷贝的,项目查询数据库报错: Could not retrieve transation read-only status server ...
- WebApi中的Session与Token间的处理对接
首先,说起来创建session,一般会针对注册登录或者授权等情况: session 从字面上讲,就是会话.这个就类似于你和一个人交谈,你怎么知道当前和你交谈的是张三而不是李四呢?对方肯定有某种特征(长 ...
- RabbitMQ随笔
不管是官方还是能搜到的文章,使用MQ的基本思路都是这样: static void Main(string[] args) { //通过工厂建立连接 using (IConnection connect ...
- iOS - 极光推送证书的创建及过期处理
无论iPhone还是安卓,我们用到的所有应用基本都有推送通知服务,因为这是应用很好的推广方式,有新产品了.有新更新了通知下用户及时查看.但Apple有点特殊,它的推送需要发到苹果服务器上中转一下,这就 ...
- Ubuntu下U盘变成只读的解决方法
首先执行命令: tail -f /var/log/syslog 然后插入有问题的U盘,tail会打印一些log: Jan :: zkw- kernel: [-: new high-speed USB ...
- 简单xmlrpc服务器
import calendar, SimpleXMLRPCServer class Calendar: def getMonth(self, year, month): return calendar ...
- day_6.14py网络编程
被动套接字和新建出套接字的区别 单任务,单线程,非阻塞!!!!服务器! #2018-6-14 16:51:25 #!--*--coding:utf-8 --*-- ''' 单进程,单任务 少的可以,多 ...
- 导入Excel 类型的数据
thinkphp 访问此控制方法就可以导入了 //数据导入 public function impUser(){ if (!empty($_FILES)) { $upload = new \Think ...