此处将为大家介绍关于如何定义带有动态子路由的vue路由器?的详细内容,并且为您解答有关动态路由vue-router的相关问题,此外,我们还将为您介绍关于Cisco路由器访问控制列表、Laravel-v
此处将为大家介绍关于如何定义带有动态子路由的 vue 路由器?的详细内容,并且为您解答有关动态路由vue-router的相关问题,此外,我们还将为您介绍关于Cisco 路由器 访问控制列表、Laravel-vuejs(Vue 路由器)Javascript 在 onchange url、NullInjectorError:R3InjectorError(AppModule)[路由器->路由器->路由器]:NullInjectorError:没有路由器的提供程序、Passport.js 与 Vue 路由器 - 导航卫士的有用信息。
本文目录一览:- 如何定义带有动态子路由的 vue 路由器?(动态路由vue-router)
- Cisco 路由器 访问控制列表
- Laravel-vuejs(Vue 路由器)Javascript 在 onchange url
- NullInjectorError:R3InjectorError(AppModule)[路由器->路由器->路由器]:NullInjectorError:没有路由器的提供程序
- Passport.js 与 Vue 路由器 - 导航卫士
如何定义带有动态子路由的 vue 路由器?(动态路由vue-router)
如何解决如何定义带有动态子路由的 vue 路由器?
我正在尝试这样的事情
{
path: "/portfolio",component: () =>
import("../common/components/Layout/Layout/Profile/ProfileLayout"),Meta: { requiresAuth: false },children: [
{
path: "/:username",component: () =>
import(/*webpackChunkName: "profile"*/ "../modules/Profile/Profile"),},],
但是当没有子路由的路由完美运行时,这段代码不起作用
{
path: "/profile/:userName",component: () => import("../modules/profile/UserProfile"),}
我如何解决第一段代码?
解决方法
您应该从子路由路径中删除前置斜线:
path: ":username",
或尝试:
path: "user/:username",
然后你可以访问像 /portfolio/user/john
Cisco 路由器 访问控制列表
实验:访问控制列表
实验目的:学习使用标准访问控制列表和扩展访问控制列表做基本的安全控制
实验拓扑:如下图
实验要求:
l 标准访问控制列表
n 不允许10.10.2.0访问172.16.1.0
n 不允许10.10.1.0访问172.16.5.0
n 允许其他所有流量
(方法不唯一,我的只供参考)
l 扩展访问控制列表
n 不允许10.10.2.0 telnet 172.16.1.0
n 不允许10.10.1.0 telnet 172.16.5.0
n 允许其他所有流量
(方法不唯一,我的只供参考)
R1的配置
R1> en
R1# config t
R1(config)# no ip routing
R1(config)# ip default-gateway 10.10.1.1
R1(config)# int e0/0
R1(config-if)# ip add 10.10.1.10 255.255.255.0
R1(config-if)# no shut
R1(config-if)# end
R1#
R2的配置
R2> en
R2# config t
R2(config)# no ip routing
R2(config)# ip default-gateway 10.10.2.1
R2(config)# int e0/3
R2(config-if)# ip add 10.10.2.10 255.255.255.0
R2(config-if)# no shut
R2(config-if)# end
R2#
R3的配置
R3> en
R3# config t
R3(config)# int e0/0
R3(config-if)# ip add 10.10.1.1 255.255.255.0
R3(config-if)# no shut
R3(config-if)# int e0/3
R3(config-if)# ip add 10.10.2.1 255.255.255.0
R3(config-if)# no shut
R3(config-if)# int e0/2
R3(config-if)# ip add 192.168.1.10 255.255.255.0
R3(config-if)# duplex full
R3(config-if)# no shut
R3(config-if)# exit
R3(config)# router ospf 10
R3(config-router)# net 0.0.0.0 255.255.255.255 area 0
R3(config-router)# end
R3#
S1的配置
S1> en
S1# config t
S1(config)# int range f0/0 - 15
S1(config-if-range)# speed 10
S1(config-if-range)# duplex full
S1(config-if-range)# no shut
S1(config-if-range)# end
S1#
R4的配置
R4> en
R4# config t
R4(config)# int e0/2
R4(config-if)# ip add 192.168.1.1 255.255.255.0
R4(config-if)# duplex full
R4(config-if)# no shut
R4(config-if)# int e0/0
R4(config-if)# ip add 172.16.1.1 255.255.255.0
R4(config-if)# no shut
R4(config-if)# exit
R4(config)# router ospf 1
R4(config-router)# net 0.0.0.0 255.255.255.255 area 0
R4(config-router)# end
R4#
R5的配置
R5> en
R5# config t
R5(config)# int e0/2
R5(config-if)# ip add 192.168.1.5 255.255.255.0
R5(config-if)# duplex full
R5(config-if)# no shut
R5(config-if)# int e0/3
R5(config-if)# ip add 172.16.5.1 255.255.255.0
R5(config-if)# no shut
R5(config-if)# exit
R5(config)# router ospf 1
R5(config-router)# net 0.0.0.0 255.255.255.255 area 0
R5(config-router)# end
R5#
R6的配置
R6> en
R6# config t
R6(config)# no ip routing
R6(config)# ip default-gateway 172.16.1.1
R6(config)# int e0/0
R6(config-if)# ip add 172.16.1.10 255.255.255.0
R6(config-if)# no shut
R6(config-if)# end
R6#
R7的配置
R7> en
R7# config t
R7(config)# no ip routing
R7(config)# ip default-gateway 172.16.5.1
R7(config)# int e0/3
R7(config-if)# ip add 172.16.5.10 255.255.255.0
R7(config-if)# no shut
R7(config-if)# end
R7#
验证:在R1上ping任意一台路由器的IP,匀能ping通,就成功了!!!
===============================================================
标准访问控制列表的配置
配置路由器R4
R4> en
R4# config t
R4(config)# access-list 1 permit 10.10.1.0 0.0.0.255
R4(config)# access-list 1 permit 192.168.1.0 0.0.0.255
R4(config)# access-list 1 permit 172.16.5.0 0.0.0.255
R4(config)# int e0/2
R4(config-if)# ip access-group 1 in
R4(config-if)# end
R4#
配置路由器R5
R5> en
R5# config t
R5(config)# access-list 1 permit 10.10.1.0 0.0.0.255
R5(config)# access-list 1 permit 192.168.1.0 0.0.0.255
R5(config)# access-list 1 permit 172.16.1.0 0.0.0.255
R5(config)# int e0/2
R5(config-if)# ip access-group 1 in
R5(config-if)# end
R5#
验证:在R1上ping 172.16.1.10 和ping 172.16.5.10 能ping通
在R2上ping 172.16.1.10 和ping 172.16.5.10 不能ping通
===================================================================
扩展访问控制列表的配置
配置路由器R4
R4> en
R4# config t
R4(config)# no access-list 1
R4(config)# int e0/2
R4(config-if)# no ip access-g roup 1 in
R4(config-if)# exit
R4(config)#
R4(config)#
R4(config)# access-list 101 deny tcp 10.10.2.0 0.0.0.255 172.16.1.0 0.0.0.255 eq 23
R4(config)# access-list 101 permit ip any any
R4(config)# int e0/2
R4(config-if)# ip access-group 101 in
R4(config-if)# end
R4#
配置路由器R5
R5> en
R5# config t
R5(config)# no access-list 1
R5(config)# int e0/2
R5(config-if)# no ip access-g roup 1 in
R5(config-if)# exit
R5(config)#
R5(config)#
R5(config)# access-list 101 deny tcp 10.10.1.0 0.0.0.255 172.16.5.0 0.0.0.255 eq 23
R5(config)# access-list 101 permit ip any any
R5(config)# int e0/2
R5(config-if)# ip access-group 101 in
R5(config-if)# end
R5#
配置路由器R6
R6> en
R6# config t
R6(config)# enable password 123
R6(config)# line vty 0 4
R6(config-line)# password 123
R6(config-line)# login
R6(config-line)# end
R6#
配置路由器R7
R7> en
R7# config t
R7(config)# enable password 123
R7(config)# line vty 0 4
R7(config-line)# password 123
R7(config-line)# login
R7(config-line)# end
R7#
验证:
(1) 在R1上能ping通172.16.1.10和172.16.5.10
(2) 在R1上能telnet到172.16.1.10,不能telnet到172.16.5.10
(3) 在R2上能ping通172.16.1.10和172.16.5.10
(4) 在R2不能telnet到172.16.1.10,能telnet到172.16.5.10
Laravel-vuejs(Vue 路由器)Javascript 在 onchange url
嗯,我明白你想要什么。您想在所有组件中调用 JavaScript 文件。例如,JavaScript 插件(如 select2、datapicker 等)的 init.js
必须在所有组件中调用,我没听错吗?
无论如何
#1 在路径 external.js
中创建文件 resources/js/
external.js
function add_script(src) {
if(document.querySelector("script[src='" + src + "']")){ return; }
let script = document.createElement('script');
script.setAttribute('src',src);
script.setAttribute('type','text/javascript');
document.body.appendChild(script)
}
function rem_script(src) {
let el = document.querySelector("script[src='" + src + "']");
if(el){ el.remove(); }
}
在您的 app.js
中添加
import {add_script,rem_script} from './external';
router.beforeEach((to,from,next) => {
/* It would be nice to add a pre-loader here d
so that the page design is not affecte
*/
// Track your console :)
console.log('Hi before load');
// Add your script
add_script('path/to/your_js');
next()
})
router.afterEach(() => {
// Here you can remove loader after loaded
// Track your console :)
console.log('Hi After load');
// remove_included_js file but still working :)
rem_script('path/to/your_js');
})
现在应该在每个组件中调用这个文件 path/to/your_js
。
完成,就是这样:)
但我从来没有在大型项目中这样建议你 :) 但正如@equi 和@Stefano A. 所说,他们是对的。
,router-link
允许在启用路由器的 JS
应用程序中进行 Vue.js
导航。这允许通过减少加载新页面所需的时间来优化用户体验。具体来说,新页面是异步注入DOM的。
为了实现您想要的结果,我们可以将我们希望在页面加载时运行的功能放在组件的 mounted()
方法中:
//component Test
<template>
<div>
<span> Test Page </span>
</div>
</template>
<script>
export default
{
data() {
return { }
},mounted() {
alert('Page loaded!'); // JS functionality to be run on component mount
}
}
</script>
如果需要,我们可以在 .js
方法中加载外部 mounted()
文件:
mounted() {
let newScript = document.createElement('script')
newScript.setAttribute('src','https://<URL>/script.js')
document.head.appendChild(newScript)
}
,
我没有看到它坏了。如果您考虑缺少警报消息:您可能将它作为 created() 或mounted() 生命周期钩子的一部分放在 App.vue 组件中。它只显示一次,因为 App.vue 组件保持加载状态,并且您正在使用路由器在 Test.vue 和 Home.vue 之间切换。 App.vue 在刷新之前不会经历其生命周期挂钩。
但是,如果您想在每次路由更改时执行部分代码,则应该在 vue 路由器上使用导航守卫。
NullInjectorError:R3InjectorError(AppModule)[路由器->路由器->路由器]:NullInjectorError:没有路由器的提供程序
将 HttpClient 导入您的 .service.ts
import { HttpClient } from '@angular/common/http';
将HttpClientModule导入app.module.ts并添加HttpClientModule导入数组
import { HttpClientModule } from '@angular/common/http';
imports: [
BrowserModule,AppRoutingModule,HttpClientModule
],
,
我在使用 @angular/router
的服务中遇到了同样的错误。我能够通过替换来修复它
@Injectable()
与
@Injectable({
providedIn: 'root'
})
在服务类中。
Passport.js 与 Vue 路由器 - 导航卫士
如何解决Passport.js 与 Vue 路由器 - 导航卫士
我使用 Vue Router 进行导航,使用passport.js 来登录/注册我的应用程序。登录/注册系统工作正常,并使用 mongodb 数据库进行设置。
但是,我无法让我的路线保护与护照功能一起使用以确保身份验证。
这是我目前的代码:
const { ensureAuthenticated } = require(''../../Configurators/userAuthentication'');
const routes = [
{path: ''/afterLogin'',name: ''AfterLogin'',component: () => import(''../views/afterLogin.vue''),beforeEnter : ensureAuthenticated},]
这是我的身份验证功能:
module.exports = {
ensureAuthenticated: function(req,res,next) {
if (req.isAuthenticated()) {
return next();
}
req.flash(''error_msg'',''Please log in to view that resource'');
res.redirect(''/users/login'');
}
};
我对 Vue Router 非常陌生,因此非常感谢您的帮助。
关于如何定义带有动态子路由的 vue 路由器?和动态路由vue-router的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Cisco 路由器 访问控制列表、Laravel-vuejs(Vue 路由器)Javascript 在 onchange url、NullInjectorError:R3InjectorError(AppModule)[路由器->路由器->路由器]:NullInjectorError:没有路由器的提供程序、Passport.js 与 Vue 路由器 - 导航卫士等相关内容,可以在本站寻找。
本文标签: