[英]Riot js using other libraries like jquery with server side rendering
I am trying to use jquery for dom manipulation on mount event of a component like this. 我正在尝试使用jquery对这样的组件的mount事件进行dom操作。
<my-tag>
<p>hi</p>
<script>
this.on('mount',funciton() {
$('.abc').hide();
})
</script>
</my-tag>
This throws an error shown below 这将引发如下所示的错误
TypeError: Cannot read property 'toString' of undefined
at ServerResponse.writeHead (_http_server.js:189:44)
If I replace 如果我更换
$(".abc").hide()
with 与
console.log("test");
This works perfectly. 这很完美。 Any idea why this is happening?
知道为什么会这样吗?
Given below are the version details 以下是版本详细信息
Riot version: 防暴版本:
riot-cli: 2.3.14 - https://github.com/riot/cli riot-cli:2.3.14- https : //github.com/riot/cli
riot-compiler: 2.3.22 - https://github.com/riot/compiler 防暴编译器:2.3.22- https ://github.com/riot/compiler
Update 更新资料
This issue happens only if if place it in this.on('mount') 仅当将其放在this.on('mount')中时,才会发生此问题
I tried placing it on this.on('all') and it works fine. 我尝试将其放在this.on('all')上 ,并且工作正常。
I don't think all
is a valid Riot event. 我认为
all
活动all
是有效的防暴活动。 As for using jQuery on the server, I'd avoid this if possible. 至于在服务器上使用jQuery,我会尽可能避免这种情况。 If you are hiding an element in your component, then you should be using Riot to switch out a CSS class.
如果要在组件中隐藏元素,则应使用Riot切换CSS类。 If this element is outside your component, you should be emitting events into an outer / global observable / pubsub handler.
如果此元素在组件外部,则应将事件发送到外部/全局可观察/ pubsub处理程序中。 If you must use jQuery you have to make sure your loading jQuery via Node's require, or using other solutions like DomJS or Cheerio.
如果必须使用jQuery,则必须确保通过Node的require或使用其他解决方案(如DomJS或Cheerio)来加载jQuery。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.