这篇文章主要为大家详细介绍了Vue.js第二天的学习笔记,关于vue-router的使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
vue中vue-router的使用:
main.js如何配置(es6的写法):在引用之前记得先 npm 下所需要的vue
import Vue from 'vue' import App from './App.vue' import Router from 'vue-rou<a>本文来源gao($daima.com搞@代@#码8网^</a>ter' 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
<title>vue.js学习笔记(2)</title> <!--此处注意加载顺序,需要先加载dom在加载js,否则会'Cannot find element: #app'--><div id='app'></div> body { }
app.vue引入router
<div class='all-container'> <div class="public-content">我是公共页面</div><div class='menu'> <ul class="list"> <li>home页面</li><li>test页面</li></ul></div></div>
home.vue
<div class="home"> <div class="htmleaf-content"> 我是home页面的内容 </div></div>
test.vue
<div class="test"> <div class="test-content"> 我是test页面的内容 </div></div>
最后用webpack 将程序打包.关于webpack大家可以看看
Vue.js――60分钟webpack项目模板快速入门
webpack主页
本文已被整理到了《Vue.js前端组件学习教程》,欢迎大家学习阅读。
以上就是Vue.js第二天学习笔记(vue-router)的详细内容,更多请关注gaodaima搞代码网其它相关文章!