简体   繁体   English

如何使用通用模式在 Nuxt 中使用 append html

[英]How to append html in Nuxt with universal mode

I try to append HTML in js file.我尝试在 js 文件中使用 append HTML 。 It was OK for SPA mode. SPA 模式没问题。

But when I change to universal mode, the HTML can't be appended.但是当我更改为通用模式时,无法附加 HTML。

Then I try to set the timeout for append function and it's Ok.然后我尝试为 append function 设置超时,没关系。 The HTML is appended successfully. HTML 附加成功。 I don't understand the reason why?我不明白为什么?

I just a new member in nuxt, so please help me explain the reason why, and how can I append HTML without set timeout?我只是nuxt的新成员,所以请帮我解释原因,以及如何在没有设置超时的情况下append HTML?

Thanks so much!非常感谢!

Without seeing the code you are using to try and implement appending html I can't be certain, but I suspect the process where the appending is to happen is taking place on the server, before it is rendered to the client.在没有看到您用来尝试执行附加 html 的代码的情况下,我无法确定,但我怀疑发生附加的过程是在服务器上发生的,然后才呈现给客户端。

To get around this you could implement the use of process.client to delay the appending.为了解决这个问题,您可以使用process.client来延迟追加。

if (process.client) {
  //do what needs to be done
}

The other option would be to use the mounted hook to call to append the html.另一种选择是使用mounted的钩子来调用 append 和 html。

As I say, if you post the code you are trying to use it would be possible to show a more detailed answer.正如我所说,如果您发布您尝试使用的代码,则可以显示更详细的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM