此项目适合不会前端,不会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实现简单项目和页面跳转的更多相关文章

  1. sharePoint中简单的父页面跳转子页面代码!

    1,SharePoint中挺简单的一个父页面跳转到子页面的Js代码!常常用到,每次都到以前的项目中去找代码,挺麻烦! (1)父页面代码. function imgAddParentclick() { ...

  2. (day68)Vue-CLI项目、页面跳转和传参、生命周期钩子

    目录 一.Vue-CLI (一)环境搭建 (二)项目的创建 (三)项目目录结构 (四)Vue组件(.vue文件) (五)全局脚本文件main.js(项目入口) (六)Vue请求生命周期 二.页面跳转和 ...

  3. angularjs项目的页面跳转如何实现

    链接:https://www.zhihu.com/question/33565135/answer/696515Angular页面传参有多种办法,根据不同用例,我举5种最常见的:PS: 在实际项目中, ...

  4. react项目中页面跳转、刷新及获取网络状态

    // 页面跳转 window.location.href = 'http://speedtest.wangxiaotong.com/' // 页面刷新 window.location.reload() ...

  5. vue路由守卫+cookie实现页面跳转时验证用户是否登录----(二)设置路由守卫

    上一篇我们已经封装好了cookie方法,登录成功之后也可以吧用户信息存到cookie中,接下来需要在router/index.js中引入一下cookie.js文件 然后继续添加以下代码 /* * be ...

  6. VUE项目实现页面跳转

    打开一个VUE项目,目录结构是这样的: 如现在有两个页面aaa和HelloWorld,路由配置在index.js中: import Vue from 'vue' import Router from ...

  7. vue 移动端项目切换页面,页面置顶

    之前项目是pc端是使用router的方式实现置顶的 //main.js router.afterEach((to, from, next) => { window.scrollTo(0, 0) ...

  8. 学习笔记-vue+quill简单的后台demo

    功能比较单一 https://github.com/opceclee/vue-quill

  9. 页面跳转(包括vue路由)

    1.JS实现页面跳转 1.1 使用window.location的href属性跳转 window.location.href = 'http://www.baidu.com';此处window可以省略 ...

随机推荐

  1. 搭建Kubernetes的web管理界面

    环境: [root@master ~]# kubectl get node NAME      STATUS    AGEnode1     Ready     5hnode2     Ready   ...

  2. ETL-拉链算法-带删除的拉链算法

    truncate table CUST;truncate table TAG_CUST; truncate table vt_inc;truncate table vt_new; insert int ...

  3. brute爆破

    0X01明文传输的表单爆破用户名和密码 不存在任何加密 直接爆破即可 当不存在用户名时: 当存在用户名时,密码错误: 这里由于靶场关了 所以我们用dvwa演示 但是dvwa没有以上的差别 所以我们默认 ...

  4. vue 2.x 的 v-bind 指令的 .prop 事件修饰符详解

    vue 官方文档对 .prop 修饰符的解释是: 使用例子: 那么,具体的原理和用法是什么呢?这要从 html 的 DOM node 说起. 在 html 标签里,我们可以定义各种 attribute ...

  5. LC 877. Stone Game

    Alex and Lee play a game with piles of stones.  There are an even number of piles arranged in a row, ...

  6. YJango的卷积神经网络——介绍

    原文地址:https://zhuanlan.zhihu.com/p/27642620 如果要提出一个新的神经网络结构,首先就需要引入像循环神经网络中“时间共享”这样的先验知识,降低学习所需要的训练数据 ...

  7. Leaflet - 实现按照路径方向旋转的 Marker

    在每帧动画时设置 Marker 的 transform 属性就行,zjffun/Leaflet.MovingMarker at zjf/feature-rotate 我在这个 Fork 中实现了一下. ...

  8. 小米监控--Open-Falcon

    #安装下载软件yum -y install wget #更换aliyun源mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Ba ...

  9. dokcer部署code-server web版vscode

    #dokcer部署code-server web版vscode codercom/code-server:latest不支持插件在线安装 codercom/code-server:v2目前为最新版1. ...

  10. Initializer for conditional binding must have Optional type, not 'String'

    今天看到问Swift问题:  Initializer for conditional binding must have Optional type, not 'String' 以前没遇到过这个问题, ...