Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

vue-router-next vue3生成的项目 打包后找不到 getCurrentInstance() 获取不到路由信息

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...