vue template中slot-scope/scope的使用方法
2019/6/27 7:43:33
本文主要是介绍vue template中slot-scope/scope的使用方法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
在vue 2.5.0+ 中slot-scope替代了 scope
template 的使用情形为,我们已经封装好一个组建,预留了插槽,使用 的插槽
首先 我们的创建一个组建
组建很简单有一个 slot,slot有两个属性 a=123,b=msg
<template> <div> <div>下面是一个slot</div> <slot a="123" b="msg" ></slot> </div> </template>
接下来我们引入组建,并使用组建,引入的组建名 为mysolt,并使用组建
然后使用 template ,并使用scope/slot-scope,
<div> <mysolt> <template scope="msg"> <div>下面是solt的props 调用</div> <div>{{msg}}</div> <div>{{msg.a}}</div> <div>{{msg.b}}</div> </template> </mysolt> </div>
渲染图如下:
其实就是 template 通过scope/slot-scope 属性 调用组建 slot 的属性,以达到可以调用组建属性实现复杂的嵌套;
实例中 我使用 msg 来重命名 slot 的属性对象,即 msg 为slot 的{a:'123',b:'msg'}, 就可以通过使用msg 在template 中使用slot的属性
(注意:当前层 如果有data已经声明过 msg,它们之间互不干扰,template 的msg 以slot 的为准)
如果我给当前 data的msg={c:111},效果图如下:
<div>{{msg.c}}</div> <mysolt> <template scope="msg"> <div>下面是solt的msg</div> <div>{{msg}}</div> <div>{{msg.a}}</div> <div>{{msg.b}}</div> <div>{{msg.c}}</div> </template> </mysolt>
以上这篇vue template中slot-scope/scope的使用方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持找一找教程网。
这篇关于vue template中slot-scope/scope的使用方法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-09vue3开发前端表单缓存自定义指令,移动端h5必备插件
- 2024-05-09React Hooks在class组件中的使用方式
- 2024-03-30[OIDC in Action] 2. 基于OIDC(OpenID Connect)的SSO(纯JS客户端)
- 2024-03-29terraform jsonencode
- 2024-03-13vuex-persist
- 2024-03-11icons for vue
- 2024-03-07breadcrumbs react js
- 2024-03-06react login page example
- 2024-03-06react router uselocation
- 2024-03-04postgres jsonb_set