簡體   English   中英

Riot js使用其他庫(例如帶有服務器端渲染的jquery)

[英]Riot js using other libraries like jquery with server side rendering

我正在嘗試使用jquery對這樣的組件的mount事件進行dom操作。

<my-tag>
    <p>hi</p>

    <script>

        this.on('mount',funciton() {
            $('.abc').hide();
        })
    </script>

</my-tag>

這將引發如下所示的錯誤

TypeError: Cannot read property 'toString' of undefined
at ServerResponse.writeHead (_http_server.js:189:44)

如果我更換

$(".abc").hide()

console.log("test");

這很完美。 知道為什么會這樣嗎?

以下是版本詳細信息

防暴版本:

riot-cli:2.3.14- https : //github.com/riot/cli

防暴編譯器:2.3.22- https ://github.com/riot/compiler

更新資料

僅當將其放在this.on('mount')中時,才會發生此問題

我嘗試將其放在this.on('all')上 ,並且工作正常。

我認為all活動all是有效的防暴活動。 至於在服務器上使用jQuery,我會盡可能避免這種情況。 如果要在組件中隱藏元素,則應使用Riot切換CSS類。 如果此元素在組件外部,則應將事件發送到外部/全局可觀察/ pubsub處理程序中。 如果必須使用jQuery,則必須確保通過Node的require或使用其他解決方案(如DomJS或Cheerio)來加載jQuery。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM