uniapp + VUE3 +setup语法糖模式,真机获取当前路由
·
下面是浏览器有用,真机没用的;
import { getCurrentInstance ,computed} from 'vue';
const {proxy} = getCurrentInstance();
const router = computed(()=> proxy.$router.currentRoute.value.fullpath)
const metaName = computed(()=> proxy.$router.currentRoute.value..meta.navigationBar.titleText)
// 在chrome浏览器好使,真机报错,
import { useRouter } from "vue-router"
const route = useRouter()
//同上,浏览器好使,真机报错
下面是真机,好使,有用;
onMounted(()=>{
//uniapp提供的方法,获取当前页面实例,以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面
const pagea = getCurrentPages();
router.value = pagea[pagea.length-1].route;
metaName.value = pagea[pagea.length-1].$page.meta.navigationBar.titleText;
console.log(router.value ,metaName.value );
})
更多推荐
所有评论(0)