我正在使用 Vue 構建網站。我使用ajax從服務器獲取資料并在前端呈現資料。內容有一些 math-jax 格式的資料,我想使用 MathJax 來處理它。但是,如果我立即像這樣呼叫 MathJax.typeset():
mounted() {
const result = getQuery("./detail/")
const app = this
result.then(function (response) {
if (response != null) {
app.$data.blog_item = response
app.$data.thumb_up_show = response.thumb_up,
app.$data.thumb_down_show = response.thumb_down
}
const mathjax = window.MathJax
// immediately call
mathjax.typeset()
})
math-jax 不會被渲染。但是如果我在呼叫 Mathjax.typeset() 之前使用 setTimeout 等待一秒鐘,那么我可以獲得正確的結果。
mounted() {
const result = getQuery("./detail/")
const app = this
result.then(function (response) {
if (response != null) {
app.$data.blog_item = response
app.$data.thumb_up_show = response.thumb_up,
app.$data.thumb_down_show = response.thumb_down
}
const mathjax = window.MathJax
// using setTimeout, which can get the right result
setTimeout(function () {
mathjax.typeset()
}, 1000)
})
雖然 setTimeout 有效,但我不想使用它。有什么辦法可以避免使用setTimeout?
uj5u.com熱心網友回復:
正如你所說,我不知道這個功能是做什么的
mathjax.typeset()
但可能你在你的方法中使用了 app.$data ,它可能會以
另一種方式導致問題,你可以嘗試 nextTick
nexttick
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/385871.html
標籤:javascript Vue.js
