Execute script when vue exists.

This commit is contained in:
qingwei.li 2017-01-24 10:06:38 +08:00
commit 9abae495ac
4 changed files with 22 additions and 10 deletions

View file

@ -98,9 +98,14 @@ export function renderArticle (content) {
renderTo('article', content ? markdown(content) : 'not found')
if (!OPTIONS.sidebar && !OPTIONS.loadSidebar) renderSidebar()
if (content && typeof Vue !== 'undefined' && typeof Vuep !== 'undefined') {
const vm = new Vue({ el: 'main' }) // eslint-disable-line
vm.$nextTick(_ => event.scrollActiveSidebar())
if (content && typeof Vue !== 'undefined') {
const script = content.match('<script[^>]*?>([^<]+)</script>')
script && document.body.querySelector('article script').remove()
const vm = script
? new Function(`return ${script[1].trim()}`)()
: new Vue({ el: 'main' }) // eslint-disable-line
vm && vm.$nextTick(_ => event.scrollActiveSidebar())
}
if (OPTIONS.auto2top) setTimeout(() => event.scroll2Top(OPTIONS.auto2top), 0)
}