From 11ea1f8d12dbf4c70221d72effaa2e90b7656d86 Mon Sep 17 00:00:00 2001 From: spiritree Date: Mon, 25 Feb 2019 09:38:56 +0800 Subject: [PATCH] fix: re-render gitalk when router changed --- src/plugins/gitalk.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/plugins/gitalk.js b/src/plugins/gitalk.js index 88d7e646d..8ba9acec6 100644 --- a/src/plugins/gitalk.js +++ b/src/plugins/gitalk.js @@ -7,10 +7,16 @@ function install(hook) { const main = dom.getNode('#main') div.style = `width: ${main.clientWidth}px; margin: 0 auto 20px;` dom.appendTo(dom.find('.content'), div) - const script = dom.create('script') - const content = `gitalk.render('gitalk-container')` - script.textContent = content - dom.appendTo(dom.body, script) + }) + + hook.doneEach(_ => { + const el = document.getElementById('gitalk-container') + while (el.hasChildNodes()) { + el.removeChild(el.firstChild) + } + + // eslint-disable-next-line + gitalk.render('gitalk-container') }) }