Vue.js框架路由使用方法实例详解

Vue.js框架路由使用方法实例详解

html代码:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta content='width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no'> <link href="https://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link type="text/css" href="https://www.jb51.net/css/css.css" /> <script src="https://www.jb51.net/lib/vue.min.js" type="text/javascript"></script> <script src="https://www.jb51.net/lib/vue-router.js" type="text/javascript" charset="utf-8"></script> <title>模仿app页面</title> </head> <body> <div> <router-view v-bind:info='info' v-bind:pic='pic' v-bind:icon='icon'></router-view> <!--底部导航--> <div> <ul> <li> <a v-on:click="show(0)"><span aria-hidden="true"></span> 首页</a> </li> <li > <a v-on:click="show(1)"><span aria-hidden="true"></span> 消息</a> </li> <li> <a v-on:click="show(2)"><span aria-hidden="true"></span> 购买</a> </li> <li> <a v-on:click="show(3)"><span aria-hidden="true"></span> 我的</a> </li> </ul> </div> </div> <!--视图页面--> <script type="text/x-template"> <div> <!--头部--> <div> <h5>这是什么app</h5> </div> <!--轮播图--> <div data-ride="carousel"> <!-- Indicators --> <ol> <li data-target="#carousel-example-generic" data-slide-to="0"></li> <li data-target="#carousel-example-generic" data-slide-to="1"></li> <li data-target="#carousel-example-generic" data-slide-to="2"></li> </ol> <!-- Wrapper for slides --> <div role="listbox"> <div> <img src="https://www.jb51.net/img/券买买_淘宝天猫优惠券_files/594781cc80d85.jpg" alt="..."> <div> ... </div> </div> <div v-for='y in pic'> <img v-bind:src='y.picUrl' alt="..."> <div> ... </div> </div> </div> <!-- Controls --> <a href="#carousel-example-generic" role="button" data-slide="prev"> <span aria-hidden="true"></span> <span>Previous</span> </a> <a href="#carousel-example-generic" role="button" data-slide="next"> <span aria-hidden="true"></span> <span>Next</span> </a> </div> <!--九宫格--> <div> <div v-for='z in icon'> <img v-bind:src="z.iurl" /> <div>{{z.name}}</div> </div> </div> <!--主页商品展示--> <div v-for='x in info'> <a v-bind:href='x.toUrl'> <div> <div><img v-bind:src='x.imgsrc' /></div> <div>{{x.info}}</div> </div> </a> </div> <div>&nbsp;</div> <div>&nbsp;</div> </div> </script> <script type="text/x-template"> <div> 这是info界面 </div> </script> <script type="text/x-template"> <div> 这是购买界面 </div> </script> <script type="text/x-template"> <div> 这是我的界面 </div> </script> <script type="text/javascript"> /*定义组件*/ const home = { template: '#home', props:{ info:Array, pic:Array, icon:Array } } const info = { template: '#info' } const goumai = { template: '#goumai' } const wode = { template:'#wode' } /*定义路由*/ const myroutes = [{ path: '/home', component: home }, { path: '/info', component: info }, { path: '/goumai', component: goumai }, { path: '/wode', component: wode }] /*创建VueRouter实例,然后传'routes'配置*/ const myr = new VueRouter({ routes: myroutes }) /*创建Vue和挂载根实例*/ const app = new Vue({ router: myr, data:{ info:[ {imgsrc:'http://img.alicdn.com/bao/uploaded/i2/TB16ybkRpXXXXXeXXXXXXXXXXXX_!!0-item_pic.jpg',info:'西麦燕麦片380克/袋装 原味纯麦片早餐 成人即食免煮冲饮无蔗糖',nav:'咖啡/麦片/冲饮',toUrl:'http://item.taobao.com/item.htm?id=534003771051'}, {imgsrc:'http://img.alicdn.com/bao/uploaded/i2/TB1SLSiRFXXXXaMXVXXXXXXXXXX_!!0-item_pic.jpg',info:'安全裤防走光女夏中高腰冰丝无痕莫代尔平角打底保险裤大码不卷边',nav:'女士内衣/男士内衣/家居服',toUrl:'http://item.taobao.com/item.htm?id=550539721556'}, {imgsrc:'http://img.alicdn.com/bao/uploaded/i4/TB1cYYHQVXXXXakXXXXXXXXXXXX_!!0-item_pic.jpg',info:'情侣装夏装韩版百搭2017新款体恤宽松半袖学生短袖T恤女潮上衣服',nav:'女装/女士精品',toUrl:'http://item.taobao.com/item.htm?id=549327457300'} ], pic:[ {picUrl:'../img/券买买_淘宝天猫优惠券_files/555737bbad955.jpg'}, {picUrl:'https://www.jb51.net/img/券买买_淘宝天猫优惠券_files/594781cc80d85.jpg'} ], icon:[ {iurl:'../img/券买买_淘宝天猫优惠券_files/5695f4aeb8a3f.png',name:'女装'}, {iurl:'../img/券买买_淘宝天猫优惠券_files/5695ff4d7bd96.png',name:'男装'}, {iurl:'../img/券买买_淘宝天猫优惠券_files/5695ff6d5b989.png',name:'内衣'}, {iurl:'../img/券买买_淘宝天猫优惠券_files/5695ff9b2eebd.png',name:'鞋子'}, {iurl:'../img/券买买_淘宝天猫优惠券_files/5695ffd10d9e3.png',name:'玩具'}, {iurl:'../img/券买买_淘宝天猫优惠券_files/569600f2bb151.png',name:'盆栽'}, {iurl:'../img/券买买_淘宝天猫优惠券_files/569600f2bb151.png',name:'首饰'}, {iurl:'../img/券买买_淘宝天猫优惠券_files/5805f0ba98f4f.png',name:'美食'}, ] }, methods: { show: function(num) { if(num == 0) { myr.push('home') } else if(num == 1) { myr.push('info') } else if(num == 2) { myr.push('goumai') }else{ myr.push('wode') } } } }).$mount('#app') window.onload = app.show(0) </script> <script src="https://www.jb51.net/js/js.js" type="text/javascript" charset="utf-8"></script> </body> </html>

css代码:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wygpgj.html