Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

import { getCurrentInstance } from "vue"
const ctxt = getCurrentInstance()
console.log(ctxt)
image
本地运行可以获取到路由信息

build打包后
image
无相关信息 找不到$router
页面报错
app.f95bcc94.js:1 Uncaught TypeError: Cannot read property 'currentRoute' of undefined
image

有没有大佬遇到了 求解决谢谢!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

//getCurrentInstance代表全局上下文,ctx相当于Vue2的this, //但是特别注意ctx代替this只适用于开发阶段,等你放到服务器上运行就会出错, //后来查阅资料说的得用proxy替代ctx,才能在你项目正式上线版本正常运行 let {ctx,proxy}=getCurrentInstance();
详细可查看这个链接https://blog.csdn.net/qq_4176...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...