如果我们想使用路由从自己的页面跳转的别人的页面,我们该怎么做,有两种方法
window.location.href = 'https://xxxxx.com/'
这个是窗口跳转
this.$router.push('/home')this.$router.push({name:'home'})this.$router.push({path:'/home'})
这些是通过在路由创建地址,进行访问,
路由代码如下
{path: '/consult',component: Layout,children: [{path: 'VaccinesSearch',name: '咨询',component: () => import('@/layout/components/VaccinesSearch')}]},
如果我想引入别人的网页在自己的项目中,而且在别人的窗口中还能返回到自己的项目,那该怎么做?
首先让我们看router的传参方法
1. 不带参数this.$router.push('/home')this.$router.push({name:'home'})this.$router.push({path:'/home'})2. query传参this.$router.push({name:'home',query: {id:'1'}})this.$router.push({path:'/home',query: {id:'1'}})// html 取参 $route.query.id// script 取参 this.$route.query.id3. params传参this.$router.push({name:'home',params: {id:'1'}}) // 只能用 name// 路由配置 path: "/home/:id" 或者 path: "/home:id" ,// 不配置path ,第一次可请求,刷新页面id会消失// 配置path,刷新页面id会保留// html 取参 $route.params.id// script 取参 this.$route.params.id4. query和params区别query类似 get, 跳转之后页面 url后面会拼接参数,类似?id=1, 非重要性的可以这样传, 密码之类还是用params刷新页面id还在params类似 post, 跳转之后页面 url后面不会拼接参数 , 但是刷新页面id 会消失
由此可以得出,通过在原生界面调取url,
link(url,title) {// window.location.href = urlthis.$router.push({path:'/consult/VaccinesSearch',query: {url,title}})}
得到标题和地址,使用iframe框架捕捉外部网页
<van-nav-bar left-text="返回" @click-left="returnn" :title="$route.query.title" ></van-nav-bar><iframe style="width: 100%;height:2000px;border: none;overflow:auto;" :src='$route.query.url'></iframe>
结果如图
