refactor(core): add router
This commit is contained in:
parent
8bee8f0213
commit
30da0d5d46
17 changed files with 316 additions and 88 deletions
|
|
@ -1,13 +1,43 @@
|
|||
import { get } from './ajax'
|
||||
import { callHook } from '../init/lifecycle'
|
||||
import { getCurrentRoot } from '../route/util'
|
||||
|
||||
export function fetchMixin (Docsify) {
|
||||
Docsify.prototype.$fetch = function (path) {
|
||||
// 加载侧边栏、导航、内容
|
||||
let last
|
||||
|
||||
Docsify.prototype._fetch = function (cb) {
|
||||
const { path } = this.route
|
||||
const { loadNavbar, loadSidebar } = this.config
|
||||
const currentRoot = getCurrentRoot(path)
|
||||
|
||||
// Abort last request
|
||||
last && last.abort && last.abort()
|
||||
|
||||
last = get(this.$getFile(path), true)
|
||||
last.then(text => {
|
||||
this._renderMain(text)
|
||||
if (!loadSidebar) return cb()
|
||||
|
||||
const fn = result => { this._renderSidebar(result); cb() }
|
||||
|
||||
// Load sidebar
|
||||
get(this.$getFile(currentRoot + loadSidebar))
|
||||
.then(fn, _ => get(loadSidebar).then(fn))
|
||||
},
|
||||
_ => this._renderMain(null))
|
||||
|
||||
// Load nav
|
||||
loadNavbar &&
|
||||
get(this.$getFile(currentRoot + loadNavbar))
|
||||
.then(
|
||||
this._renderNav,
|
||||
_ => get(loadNavbar).then(this._renderNav)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export function initFetch (vm) {
|
||||
vm.$fetch(result => {
|
||||
vm._fetch(result => {
|
||||
vm.$resetEvents()
|
||||
callHook(vm, 'doneEach')
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue