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

vue 3.4.5 路由问题 #678

Open
Tracked by #679
qingmang opened this issue Feb 5, 2024 · 8 comments
Open
Tracked by #679

vue 3.4.5 路由问题 #678

qingmang opened this issue Feb 5, 2024 · 8 comments
Assignees
Labels
🐞 BUG Something isn't working To be published

Comments

@qingmang
Copy link

qingmang commented Feb 5, 2024

tdesign-vue-next-starter 版本

last

重现链接

No response

重现步骤

最新版本路由不跳转的bug

期望结果

改一下APP.vue 的key 改成route.path

实际结果

image

框架版本

No response

浏览器版本

No response

系统版本

No response

Node版本

No response

补充说明

正经了

Copy link

github-actions bot commented Feb 5, 2024

👋 @qingmang,感谢给 TDesign 提出了 issue。
请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

Copy link

github-actions bot commented Feb 5, 2024

♥️ 有劳 @timi137137 @liweijie0812 尽快确认问题。
确认有效后将下一步计划和可能需要的时间回复给 @qingmang

@timi137137
Copy link
Collaborator

vue3.4暂不处理,等vue3.4稳定后再做处理

@timi137137 timi137137 added 🐞 BUG Something isn't working ⏹ Pending This issue is pending labels Feb 5, 2024
@w6et
Copy link

w6et commented Mar 29, 2024

vue3.4暂不处理,等vue3.4稳定后再做处理

[非前端,以下内容不完全保证]
@timi137137
不确定vue官方会不会把这个视为bug,因为关于route、router的使用,是要求在setup里使用的,可能需要某种方式的hooks,或者直接把需要的route属性值传给后面的函数,试了一下,在setup里取到route,传给后面是ok的。
setup里使用route,我试了以下3种方式都是ok
1)import { useRoute } from 'vue-router';
const route=useRoute();
在<script setup>里用route,还是在template上直接:a1="route.path"都行
2)import { getCurrentInstance,ComponentInternalInstance} from 'vue';
const { proxy } = getCurrentInstance() as ComponentInternalInstance
通过proxy.$route获取
3)在template上直接:a2="this.$route.path"
3种方式,那种更推荐不确定

@timi137137
Copy link
Collaborator

vue3.4暂不处理,等vue3.4稳定后再做处理

[非前端,以下内容不完全保证] @timi137137 不确定vue官方会不会把这个视为bug,因为关于route、router的使用,是要求在setup里使用的,可能需要某种方式的hooks,或者直接把需要的route属性值传给后面的函数,试了一下,在setup里取到route,传给后面是ok的。 setup里使用route,我试了以下3种方式都是ok 1)import { useRoute } from 'vue-router'; const route=useRoute(); 在<script setup>里用route,还是在template上直接:a1="route.path"都行 2)import { getCurrentInstance,ComponentInternalInstance} from 'vue'; const { proxy } = getCurrentInstance() as ComponentInternalInstance 通过proxy.$route获取 3)在template上直接:a2="this.$route.path" 3种方式,那种更推荐不确定

image
我不太清楚你想表达的意思是...?

@w6et
Copy link

w6et commented Mar 29, 2024

我不太清楚你想表达的意思是...?
这个文件:
/tdesign-vue-next-starter/src/router/index.ts的getActive方法里直接调用了useRoute()

我的意思是:不能在自定义函数里直接用useRoute(),route要在vue文件里的setup方法里用
后面给的3个在setup里用route的例子,只是我不太清楚那种方式合适,可以当作是发出来咨询一下。

@timi137137
Copy link
Collaborator

我不太清楚你想表达的意思是...?
这个文件:
/tdesign-vue-next-starter/src/router/index.ts的getActive方法里直接调用了useRoute()

我的意思是:不能在自定义函数里直接用useRoute(),route要在vue文件里的setup方法里用 后面给的3个在setup里用route的例子,只是我不太清楚那种方式合适,可以当作是发出来咨询一下。

第一种方法就是目前通用主流方法,第二种方法要去获取VUE实例,走反射不如直接从router抓实例对象,省内存
第三种方法只适用于模板内,而不是script

@timi137137
Copy link
Collaborator

我不太清楚你想表达的意思是...?
这个文件:
/tdesign-vue-next-starter/src/router/index.ts的getActive方法里直接调用了useRoute()

我的意思是:不能在自定义函数里直接用useRoute(),route要在vue文件里的setup方法里用 后面给的3个在setup里用route的例子,只是我不太清楚那种方式合适,可以当作是发出来咨询一下。

最后经过讨论和测试后发现,虽然两个方法内部指向一致,但是因为useRoute方法需要由setup语法糖进行初始化,而在该定义方法内并没有初始化对应实例导致出现未定义的问题,故你说的是对的,采用router实例对象获取当前路由对象的方式修复问题,感谢你的贡献

@timi137137 timi137137 added To be published and removed ⏹ Pending This issue is pending labels Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 BUG Something isn't working To be published
Projects
None yet
Development

No branches or pull requests

4 participants