源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Vue.js第二天学习笔记(vue-router)

  • 时间:2022-04-11 13:22 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Vue.js第二天学习笔记(vue-router)
vue中vue-router的使用: [img]http://files.jb51.net/file_images/article/201612/2016121153657757.jpg?201611115377[/img] [img]http://files.jb51.net/file_images/article/201612/2016121153718319.jpg?2016111153725[/img] [img]http://files.jb51.net/file_images/article/201612/2016121153731893.jpg?2016111153738[/img] main.js如何配置(es6的写法):在引用之前记得先   npm 下所需要的vue
import Vue from 'vue'
import App from './App.vue'
import Router from 'vue-router'
import Resource from 'vue-resource'
//import VueTouch from 'vue-touch'
var VueTouch = require('vue-touch')

//引入home页面
import homepage from './page/home.vue'
//引入test页面
import test from './page/test.vue'

Vue.use(Router);
Vue.use(Resource);
Vue.use(VueTouch);

var router = new Router({
 abstract: true,
 hashbang: false
});
//实现页面跳转
router.map({
 '/home':{
 component:homepage
 }, 
 '/test':{
 component:test
 }, 
 
})

router.start(App, '#app')
// router.go('test'); 默认直接跳转到 test 页面

index.html中引入app.vue和build.js
<!DOCTYPE html>
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>vue.js学习笔记(2)</title>
 <link rel="stylesheet" type="text/css" href="style/bootstrap.css">
</head>
<body>
 <!--此处注意加载顺序,需要先加载dom在加载js,否则会'Cannot find element: #app'-->
 <div id='app'></div>
 <script src="static/build.js"></script>
</body>
</html>
<style>
body {
}
</style>
app.vue引入router
<template>
<div class='all-container'>
 <div class="public-content">我是公共页面</div>
 <div class='menu'>
 <ul class="list">
 <li><a v-link='"/home"'>home页面</a></li>
 <li><a v-link='"/test"'>test页面</a></li>
 </ul>
 </div>
 <router-view transition='animation' class='container' keep-alive></router-view>
</div>
</template>
home.vue
<template>
<div class="home">
 <div class="htmleaf-content">
 我是home页面的内容
 </div>
</div>
</template>
test.vue
<template>
<div class="test">
 <div class="test-content">
我是test页面的内容
</div>
</div>

</template>

 最后用webpack 将程序打包.关于webpack大家可以看看 [url=http://www.cnblogs.com/keepfool/p/5678427.html]Vue.js——60分钟webpack项目模板快速入门[/url] [url=http://webpack.github.io/]webpack主页[/url] 本文已被整理到了《[url=http://www.1sucai.cn/Special/874.htm]Vue.js前端组件学习教程[/url]》,欢迎大家学习阅读。 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部