【笔记】vue实现简单项目和页面跳转
此项目适合不会前端,不会vue的人。
不会vue真正的开发,这里用vue和vant-ui简单搭一个商城app的tabbar和页面跳转。
装vue-cli3.0
根据官网快速上手搭建vant项目,官网
命令行vue ui开启可视化的依赖管理,(把什么bubble eslint这些没用的依赖全部删掉,转个vue-router插件,然后回到项目会自动生成views文件夹和router文件夹。
在component文件夹下新建一个vue文件 TabBar.vue
<template>
<div id="z-tabbar">
<van-tabbar v-model="active">
<van-tabbar-item icon="home-o" to="/">首页</van-tabbar-item>
<van-tabbar-item icon="search" to="search">搜索</van-tabbar-item>
<van-tabbar-item icon="shopping-cart-o" to="cart">购物车</van-tabbar-item>
<van-tabbar-item icon="friends-o" to="me">个人中心</van-tabbar-item>
</van-tabbar>
</div>
</template> <script>
import 'vant/lib/tabbar/style';
import 'vant/lib/tabbar-item/style';
import Vue from 'vue';
import { Tabbar, TabbarItem } from 'vant';
Vue.use(Tabbar).use(TabbarItem);
export default {
name: "TabBar",
data() {
return {
active: 0
}
},
methods:{ },
mounted() {
var str = this.$route.path;
//根据路由判断active
if(str==='/'){
this.active=0;
}else if (str === '/search') {
this.active = 1
} else if (str === '/cart') {
this.active = 2
} else if (str === '/me') {
this.active = 3;
}
}
}
</script>
<style scoped>
</style>
在views文件夹下新建要跳转的页面对应的vue文件。
<template>
<div>
<van-nav-bar title="购物车"/>
<div>Cart</div>
</div>
</template> <script>
export default {
name: "Cart"
}
</script> <style scoped> </style>
<template>
<div>
<van-nav-bar title="个人中心"/>
<div>Me</div>
</div>
</template> <script>
export default {
name: "Me"
}
</script> <style scoped> </style>
修改App.vue
<template>
<div id="app">
<router-view/>
<TabBar></TabBar>
</div>
</template> <style>
</style>
<script>
import TabBar from "./components/TabBar";
export default {
components: {TabBar}
}
</script>
修改router文件夹下的index.js文件,配置路由。
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Search from "../views/Search";
import Cart from "../views/Cart";
import Me from "../views/Me"; Vue.use(VueRouter) const routes = [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/search',
name: 'search',
component: Search
},
{
path: '/cart',
name: 'cart',
component: Cart
},
{
path: '/me',
name: 'me',
component: Me
},
] const router = new VueRouter({
routes
}) export default router
结果

【笔记】vue实现简单项目和页面跳转的更多相关文章
- sharePoint中简单的父页面跳转子页面代码!
1,SharePoint中挺简单的一个父页面跳转到子页面的Js代码!常常用到,每次都到以前的项目中去找代码,挺麻烦! (1)父页面代码. function imgAddParentclick() { ...
- (day68)Vue-CLI项目、页面跳转和传参、生命周期钩子
目录 一.Vue-CLI (一)环境搭建 (二)项目的创建 (三)项目目录结构 (四)Vue组件(.vue文件) (五)全局脚本文件main.js(项目入口) (六)Vue请求生命周期 二.页面跳转和 ...
- angularjs项目的页面跳转如何实现
链接:https://www.zhihu.com/question/33565135/answer/696515Angular页面传参有多种办法,根据不同用例,我举5种最常见的:PS: 在实际项目中, ...
- react项目中页面跳转、刷新及获取网络状态
// 页面跳转 window.location.href = 'http://speedtest.wangxiaotong.com/' // 页面刷新 window.location.reload() ...
- vue路由守卫+cookie实现页面跳转时验证用户是否登录----(二)设置路由守卫
上一篇我们已经封装好了cookie方法,登录成功之后也可以吧用户信息存到cookie中,接下来需要在router/index.js中引入一下cookie.js文件 然后继续添加以下代码 /* * be ...
- VUE项目实现页面跳转
打开一个VUE项目,目录结构是这样的: 如现在有两个页面aaa和HelloWorld,路由配置在index.js中: import Vue from 'vue' import Router from ...
- vue 移动端项目切换页面,页面置顶
之前项目是pc端是使用router的方式实现置顶的 //main.js router.afterEach((to, from, next) => { window.scrollTo(0, 0) ...
- 学习笔记-vue+quill简单的后台demo
功能比较单一 https://github.com/opceclee/vue-quill
- 页面跳转(包括vue路由)
1.JS实现页面跳转 1.1 使用window.location的href属性跳转 window.location.href = 'http://www.baidu.com';此处window可以省略 ...
随机推荐
- DOM对象属性
事件 onmouseover 鼠标以上事件 onmouseout 鼠标离开事件 onclock 鼠标点击事件 onfocus 获取焦点 onblur 失去焦点 oninput 输入事件 ...
- Java并发编程(十一)——原子操作CAS
一.原子操作 syn基于阻塞的锁的机制,1.被阻塞的线程优先级很高,2.拿到锁的线程一直不释放锁怎么办?3.大量的竞争,消耗cpu,同时带来死锁或者其他安全. CAS的原理 CAS(Compare A ...
- zookeeper系列(八)zookeeper客户端的底层详解
作者:leesf 掌控之中,才会成功:掌控之外,注定失败.出处:http://www.cnblogs.com/leesf456/p/6098255.html 尊重原创,共同学习进步: 一.前言 ...
- DB 分库分表(3):关于使用框架还是自主开发以及 sharding 实现层面的考量
当团队对系统业务和数据库进行了细致的梳理,确定了切分方案后,接下来的问题就是如何去实现切分方案了,目前在sharding方面有不少的开源框架和产品可供参考,同时很多团队也会选择自主开发实现,而不管是选 ...
- 苹果应用(.ipa)打包和上传,不用通过苹果商店即可用
签名工具: appuploader(.p12:.cer) 打包平台: http://www.lbuilder.com(收费) 上传平台: http://www.58apk.com (每日50次下载,加 ...
- How to change the button text of <input type=“file” />?
How to change the button text of <input type=“file” />? Simply <label class="btn btn-p ...
- How to intercept any postback in a page? - ASP.NET
How to intercept any postback in a page? - ASP.NET There's a couple of things you can do to intercep ...
- Java工具类-HttpUtil
package com.sh.util; import java.io.IOException; import java.io.UnsupportedEncodingException; import ...
- .net中错误日志的写入
18 public static void SaveError(Exception ex,HttpContext hc,HttpRequest hr)19 {20 string temp ; ...
- OGG-01201
OGG-01201 Table of Contents 1. OGG-01201 1.1. 案例1 1.2. 案例2 1 OGG-01201 这种错误,出现的场景之一是 direct load 加载数 ...