VUE3.0使用组合api进行路由跳转
程序员文章站
2022-03-04 10:45:56
...
1)template模板内容,给button按钮绑定一个click
<el-button class="btn—confirm" type="primary" @click="handleSearch()">
登录
</el-button>
2)在此组件的script中引入userouter
import { useRouter } from "vue-router";
3)定义userouter为router
const router = useRouter();
4)handleSearch()实现路由跳转
const handleSearch = () => {
console.log('123')
router.push('/home/search');
}
5)将handleSearch()方法暴露出去
return {
handleSearch
};