Ai
2 Star 0 Fork 0

Fictiony Chen/MySplitter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vueext.js 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
Fictiony Chen 提交于 2021-04-12 11:25 +08:00 . update vueext.js.
import Vue from 'vue'
Object.assign(Vue.prototype, {
// 注入插槽
// - @slot 插槽名
// - @id 注入ID(相同ID的注入将被替换而非新增,但一前一后则可共存)
// - @nodes 要注入的节点列表(null表示删除该注入)
// - @before 是否加到最前面(否则加到最后面),替换时位置不变
$injectSlot(slot, id, nodes, before = false) {
const injection = { id, nodes }
const f = this.$scopedSlots[slot]
if (f && f.__origSlot) {
const side = before ? f.__injectBefore : f.__injectAfter
const index = side.findIndex(item => item.id === id)
if (index < 0) {
if (before) {
side.unshift(injection)
} else {
side.push(injection)
}
} else {
side[index] = injection
}
} else {
const injected = props => {
return [
injected.__injectBefore.flatMap(item => item.nodes || []),
injected.__origSlot && injected.__origSlot(props),
injected.__injectAfter.flatMap(item => item.nodes || [])
].flat()
}
injected.__origSlot = f
injected.__injectBefore = before ? [injection] : []
injected.__injectAfter = before ? [] : [injection]
this.$scopedSlots[slot] = injected
}
}
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fictiony/mysplitter.git
git@gitee.com:fictiony/mysplitter.git
fictiony
mysplitter
MySplitter
master

搜索帮助