vue-cli搭建后如何加入新页面
来源:互联网 发布:淘宝自己的评价怎么看 编辑:程序博客网 时间:2024/06/03 18:13
使用vue-router配置路由 在vue根实例中注入
import Vue from 'vue'import VueRouter from 'vue-router'import topNav from '../components/topNav'import mine from '../components/mine'import searchPage from '../components/searchPage'import searchResult from '../components/searchResult'import playPage from '../components/playPage'import playbottom from '../components/playbottom'import latestPlay from '../components/latestPlay'Vue.use(VueRouter)const router = new VueRouter({ routes: [ { path: '/', component: mine }, { path: '/mine', component: mine }, { path: '/mine/searchPage', component: searchPage }, { path: '/mine/searchPage/searchResult', component: searchResult }, { path: '/playPage', component: playPage }, { path: '/latestPlay', component: latestPlay } ]})export default router
import router from '../router'var app = new Vue({ el: "#app1", router, store: vuex_store,})
大概就是这样 链接用<router-link to="/play"></router-link>这样
昨天温故了一下vue2.0的路由 做个笔记简单记录一下!
1.首相和vue1.0一样 要使用vuejs的路由功能需要先引入vue-router.js
2.然后修改原有a标签处代码 这里以一个ul li a 为例
<ul> <li><a href="#"></a></li> <li><a href="#"></a></li></ul>
使用 router-link标签替换原有a标签出 router-link会默认生成一个a标签 里面的to="" 指的是访问 to="home" 就是访问home, to="news" 就是访问news 经过改装后代码如下
<ul> <li><router-link to="/home">主页</router-likn></li> <li><router-link to="/news">新闻</router-likn></li></ul>
3.在第一步的时候引入了vue-router.js 现在需要创建一个 路由的实例
const router = new VueRouter({ routes })
上面的routes是具体的路由配置信息具体配置如下
const routes = [ {path:'/home',component:Home}, {path:'/news',component:News} ]
path指的是访问的网址 对应上面<router-link to="xxx">里的to属性,后面component指的是对应模板
4.最后需要在调用出指定我们定义的上述定义的router
new Vue({ router, el:'xxxx' })
总结:总体来讲vue2.0比起老版本要简单很多
阅读全文
0 0
- vue-cli搭建后如何加入新页面
- vue打开新页面
- (vue:案例02) vue-cli 如何搭建项目
- Vue-cli 搭建指南
- vue-cli 环境搭建
- vue-cli搭建项目
- vue-cli的搭建
- vue-cli 项目搭建
- vue-cli 脚手架搭建
- vue-cli搭建项目
- 搭建vue-cli脚手架
- cli 搭建Vue 环境
- Vue 搭建脚手架--vue-cli
- vue-cli搭建vue项目
- webpack搭建的vue-cli项目如何使用sass?
- vue-cli脚手架的搭建
- vue-cli环境搭建配置
- 使用 vue-cli 搭建项目
- Sentry--错误日志收集框架
- vue2.0组件之间如何通信
- animate cc在ios上点击canvas闪黑以及在安卓微信里巨卡的解决方案
- 曾被雷军点赞的00后CEO回国融资:没钱发工资!和贾跃亭不一样
- mybatis关于传递参数问题
- vue-cli搭建后如何加入新页面
- TensorFlow on Android:训练模型
- C++总结笔记
- 小蓝单车CEO父亲“顶雷”:谁要钱给谁打工
- 外媒称这是今年最好的15款智能手机!iPhone X都只排第4
- 解决Spring中Quart无法自动注入Bean问题
- 图解机器学习
- 使用Fiddler抓Android应用的包
- laravel中防止表单重复提交的综合解决方案