getScopedSlot_mixin
当组件使用的是 render 函数时,getScopedSlot_mixin 提供一些方法来定义作用域插槽和获取插槽的内容
# 需独立引入
import getScopedSlot_mixin from 'yb-components/packages/es/mixins/getScopedSlot_mixin';
export default {
mixins: [getScopedSlot_mixin],
};
1
2
3
4
5
2
3
4
5
# 提供的 methods
# this.getScopedSlot(slotName)
从this.$scopedSlots
获取作用域插槽函数的方法
参数:
{string} slotName,插槽名称,支持格式:"title"、"title||titles"
返回值:
{function} scopeSlot or null
用法:
this.$scopedSlots
可能的情况是:
- {"title":function(data){return Node}}
- {"title,name":function(data){return Node}}
- {"titles":function(data){return Node}}
以上三种可能情况,都能获取到 titleSlot
import getScopedSlot_mixin from 'yb-components/packages/es/mixins/getScopedSlot_mixin';
export default {
mixins: [getScopedSlot_mixin],
render(h) {
const titleSlot = this.getScopedSlot('title||titles');
return titleSlot ? titleSlot({ data: 'a' }) : null;
},
};
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# this.getScopeSlotFromMult(slotName)
从this.$scopedSlots
获取作用域插槽函数的方法
参数:
{string} slotName,插槽名称,支持格式:"title"
返回值:
{function} scopeSlot or null
用法:
this.$scopedSlots
可能的情况是:
- {"title":function(data){return Node}}
- {"title,name":function(data){return Node}}
以上两种可能情况,都能获取到 titleSlot
import getScopedSlot_mixin from 'yb-components/packages/es/mixins/getScopedSlot_mixin';
export default {
mixins: [getScopedSlot_mixin],
render(h) {
const titleSlot = this.getScopeSlotFromMult('title');
return titleSlot ? titleSlot({ data: 'a' }) : null;
},
};
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# this.getScopedSlotValue(scopeSlot, [scopedData], [defaultNode])
调用 scopeSlot 函数得到插槽内容
参数:
{function} scopeSlot,插槽函数
{object} [scopedData], 传入 scopeSlot 的参数
{string|number|vNode} [defaultNode],插槽函数没有返回值的默认内容
返回值:
{string|number|vNode} scopeValue
用法:
import getScopedSlot_mixin from 'yb-components/packages/es/mixins/getScopedSlot_mixin';
export default {
mixins: [getScopedSlot_mixin],
render(h) {
const titleSlot = this.getScopedSlot('title');
return this.getScopedSlotValue(titleSlot, { data: 'a' }, 'b');
},
};
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
上次更新: 2022/05/22, 22:22:27