<router-view></router-view>
const myRoutes = [
{path:'/myLogin',component:TestLogin},
{path:'/myRegister',component:TestRegister}
]
const myRouter = new VueRouter({
routes:myRoutes
})
new Vue({
router:myRouter
})
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/vue.js"></script>
<!-- 引入文件 -->
<script src="js/vue-router.js"></script>
</head>
<body>
<div id="container">
<p>{{msg}}</p>
<!--通过router-view指定盛放组件的容器 -->
<router-view></router-view>
</div>
<script>
var testLogin = Vue.component("login",{
template:`
<div>
<h1>这是我的登录页面</h1>
</div>
`
})
var testRegister = Vue.component("register",{
template:`
<div>
<h1>这是我的注册页面</h1>
</div>
`
})
//配置路由词典
//对象数组
const myRoutes =[
//当路由地址:地址栏中的那个路径是myLogin访问组件
//组件是作为标签来用的所以不能直接在component后面使用
//要用返回值
//path:''指定地址栏为空:默认为Login页面
{path:'',component:testLogin},
{path:'/myLogin',component:testLogin},
{path:'/myRegister',component:testRegister}
]
const myRouter = new VueRouter({
//myRoutes可以直接用上面的数组替换
routes:myRoutes
})
new Vue({
router:myRouter,
//或者:
/*
router:new VueRouter({
routes:[
{path:'/myLogin',component:testLogin},
{path:'/myRegister',component:testRegister}
]
})
*/
el:"#container",
data:{
msg:"Hello VueJs"
}
})
</script>
</body>
</html>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>SPA练习</title>
<script src="js/vue.js"></script>
<script src="js/vue-router.js"></script>
</head>
<body>
<div id="container">
<p>{{msg}}</p>
<router-view></router-view>
</div>
<script>
/*
需要大家创建一个SPA,这个SPA有3个组件,分别对应的是collect/detail/order
功能需求:
在地址栏中路由地址是:
/myColllect --> 收藏页组件
/myDetail --> 详情页组件
/myOrder --> 订单页组件
*/
/*
1、引入js文件
2、创建三个组件,需要返回值
3、路由词典配置(三小步)const myRoutes、const myRouter、router:myRouter,
4、指定一个盛放代码片段的容器
<router-view></router-view>
*/
var testCollect = Vue.component("collect",{
template:`
<div>
<h1>这是收藏页</h1>
</div>
`
})
var testDetail = Vue.component("detail",{
template:`
<div>
<h1>这是详情页</h1>
</div>
`
})
var testOrder = Vue.component("order",{
template:`
<div>
<h1>这是订单页</h1>
</div>
`
})
const myRoutes = [
{path:"",component:testCollect},
{path:"/myColllect",component:testCollect},
{path:"/myDetail",component:testDetail},
{path:"/myOrder",component:testOrder},
]
const myRouter = new VueRouter({
routes:myRoutes
})
new Vue({
router:myRouter,
el:"#container",
data:{
msg:"Hello VueJs"
}
})
</script>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有