vue 路由器未定义
vue router is undefined
http://localhost:3000/apartamentai?filter[city]=维尔纽斯
import { ref, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
export default {
setup() {
const router = useRouter();
const route = useRoute();
console.log(router);
console.log(route);
onMounted(() => {
console.log(router);
console.log(route);
});
}
}
我得到 4 undefined
。怎么了?
https://next.router.vuejs.org/guide/advanced/composition-api.html
您必须在您的应用中创建并注册路由器:
import { createApp } from 'vue';
import { createRouter, createWebHistory } from 'vue-router';
const router = createRouter({
mode: 'history',
history: createWebHistory(),
routes: [],
});
createApp({})
.use(router)
.mount('#app');
http://localhost:3000/apartamentai?filter[city]=维尔纽斯
import { ref, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
export default {
setup() {
const router = useRouter();
const route = useRoute();
console.log(router);
console.log(route);
onMounted(() => {
console.log(router);
console.log(route);
});
}
}
我得到 4 undefined
。怎么了?
https://next.router.vuejs.org/guide/advanced/composition-api.html
您必须在您的应用中创建并注册路由器:
import { createApp } from 'vue';
import { createRouter, createWebHistory } from 'vue-router';
const router = createRouter({
mode: 'history',
history: createWebHistory(),
routes: [],
});
createApp({})
.use(router)
.mount('#app');