Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

从服务器请求数据,如果数据为空,则调用this.$route方法来打开添加页,有时不起作用 #34

Open
myjf007 opened this issue Jan 11, 2019 · 4 comments

Comments

@myjf007
Copy link

myjf007 commented Jan 11, 2019

rq(opt).then( res => {
wx.hideToast();
const data = res.data;
if (data.code === 200 ) {
}else {
this.$route('../add/add');
/wx.navigateTo({
url: '../add/add'
})
/
}
}).catch(()=>{
wx.hideToast();
})

@myjf007
Copy link
Author

myjf007 commented Jan 11, 2019

如果把this.$route换成wx.navigateTo那就正常跳转

@switer
Copy link
Member

switer commented Jan 12, 2019

$route是框架封装的跳转接口,路径是有限制的。

用法:$route(pagename[, config])

this.$route('play?vid=xxx&cid=xxx');

@myjf007
Copy link
Author

myjf007 commented Jan 12, 2019

我配置的是
wxpage.A({ config:{ route: '/pages/$page/$page' } })
如果我按
this.$route('add');
这样来跳转,会直接报找不到文件
只能按下面这个方式来
this.$route('../add/add');
才可以,而且必须是放在
onReady才正常,
如果放在
onLoad
的话,会时好时坏

@switer
Copy link
Member

switer commented Jan 18, 2019

route: '/pages/$page/$page' 实际上是告诉框架,怎样取到正确的页面路径,

在上述配置中,this.$route('add');实际上会被转换为

wx.navigateTo({url: '/pages/add/add'})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants