gpt4 book ai didi

javascript - 如何使用通过 riot.route() 获得的参数?

转载 作者:行者123 更新时间:2023-11-28 05:21:54 27 4
gpt4 key购买 nike

riot.route('/*', function(category) {
riot.mount('#main', 'category-page', category)
})

当URL更改时,我想获取参数作为“类别”并在 <category-page> 中使用它。我试过console.log(this.opts.category)<category-page> ,但我得到的是未定义的。

riot.route('/*', function(category) {
riot.mount('#main', 'category-page', category)
console.log(category)
})

当我像上面那样编码时,console.log(category)效果很好。所以我认为传递或获取参数是错误的。我尝试了很多案例,但无法解决。请帮我解决这个问题。

最佳答案

调用时根据riot.js router api文档riot.mount(selector, tagName, [opts]) 您应该传递一个将在标记中设置为 this.opts 的对象。

所以你的路由器代码应该如下所示:

riot.route('/*', function(category) {
riot.mount('#main', 'category-page', {category: category})
});

关于javascript - 如何使用通过 riot.route() 获得的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40482671/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com