如题,想在setup script语法中监听 路由信息没有找到 beforeRouterEnter的用法
如题,想在setup script语法中监听 路由信息没有找到 beforeRouterEnter的用法
无法直接在<script setup>
中使用,只能用两个script
标签
<script lang="ts">
import { defineComponent, ComponentPublicInstance } from 'vue'
interface IInstance extends ComponentPublicInstance {
setPathFrom(from: string): void
}
export default defineComponent({
beforeRouteEnter(to, from, next) {
next((vm) => {
const instance = vm as IInstance
instance.setPathFrom(from.path)
})
},
})
</script>
<script lang="ts" setup>
let pathFrom: string
const setPathFrom = (path: string) => {
pathFrom = path
console.log('vue-route::from::', pathFrom)
}
defineExpose({ setPathFrom })
</script>
github 有个讨论的帖子Usage of beforeRouteEnter with <script setup>
3 回答3.3k 阅读✓ 已解决
1 回答2.2k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
2 回答1.8k 阅读✓ 已解决
1 回答2.1k 阅读✓ 已解决
5 回答2k 阅读
2 回答1.1k 阅读✓ 已解决
安装:npm i unplugin-vue-define-options -D
配置 vite.config.ts
之后可以在项目中定义option项: