riot.route('/*', function(category) {
riot.mount('#main', 'category-page', category)
})当URL更改时,我希望获得参数作为“类别”,并在<category-page>中使用它。我尝试了console.log(this.opts.category)in <category-page>,但我得到的是未定义的。
riot.route('/*', function(category) {
riot.mount('#main', 'category-page', category)
console.log(category)
})当我像上面这样编码时,console.log(category)工作得很好。所以我认为传递或获取参数是错误的。我试了很多次,但都没能解决。请帮我解决这个问题。
发布于 2016-11-08 16:28:17
根据riot.js路由器api文档,在调用riot.mount(selector, tagName, [opts])时,应该传递一个对象,该对象将在标记中设置为this.opts。
所以您的路由器代码应该如下所示:
riot.route('/*', function(category) {
riot.mount('#main', 'category-page', {category: category})
});https://stackoverflow.com/questions/40482671
复制相似问题