fix(render): init event in ssr
This commit is contained in:
parent
3444884905
commit
eba1c987a8
6 changed files with 68 additions and 12 deletions
|
|
@ -2,6 +2,7 @@ import { get } from './ajax'
|
|||
import { callHook } from '../init/lifecycle'
|
||||
import { getParentPath } from '../router/util'
|
||||
import { noop } from '../util/core'
|
||||
import { getAndActive } from '../event/sidebar'
|
||||
|
||||
function loadNested (path, file, next, vm, first) {
|
||||
path = first ? path : path.replace(/\/$/, '')
|
||||
|
|
@ -70,7 +71,15 @@ export function fetchMixin (proto) {
|
|||
}
|
||||
|
||||
export function initFetch (vm) {
|
||||
const { loadSidebar } = vm.config
|
||||
|
||||
// server-client renderer
|
||||
if (vm.rendered) {
|
||||
const activeEl = getAndActive(vm.router, '.sidebar-nav', true, true)
|
||||
if (loadSidebar && activeEl) {
|
||||
activeEl.parentNode.innerHTML += window.__SUB_SIDEBAR__
|
||||
}
|
||||
vm._bindEventOnRendered(activeEl)
|
||||
vm._fetchCover()
|
||||
vm.$resetEvents()
|
||||
callHook(vm, 'doneEach')
|
||||
|
|
|
|||
|
|
@ -54,10 +54,6 @@ function renderMain (html) {
|
|||
} else {
|
||||
this.config.executeScript && executeScript()
|
||||
}
|
||||
|
||||
if (this.config.auto2top) {
|
||||
scroll2Top(this.config.auto2top)
|
||||
}
|
||||
}
|
||||
|
||||
function renderNameLink (vm) {
|
||||
|
|
@ -91,7 +87,12 @@ export function renderMixin (proto) {
|
|||
activeEl.parentNode.innerHTML += this.compiler.subSidebar(subMaxLevel)
|
||||
}
|
||||
// bind event
|
||||
this.activeLink = activeEl
|
||||
this._bindEventOnRendered()
|
||||
}
|
||||
|
||||
proto._bindEventOnRendered = function (activeEl) {
|
||||
const { autoHeader, auto2top } = this.config
|
||||
|
||||
scrollActiveSidebar(this.router)
|
||||
|
||||
if (autoHeader && activeEl) {
|
||||
|
|
@ -103,6 +104,8 @@ export function renderMixin (proto) {
|
|||
dom.before(main, h1)
|
||||
}
|
||||
}
|
||||
|
||||
auto2top && scroll2Top(auto2top)
|
||||
}
|
||||
|
||||
proto._renderNav = function (text) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ export class HTML5History extends History {
|
|||
}
|
||||
|
||||
getCurrentPath () {
|
||||
const base = this.config.base
|
||||
const base = this.config.basePath
|
||||
let path = window.location.pathname
|
||||
|
||||
if (base && path.indexOf(base) === 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue