【笔记】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可以省略 ...
随机推荐
- PHP中获取数组中单列的值
PHP中获取数组中单列的值如下: 利用PHP中的数组函数 array_column():返回数组中某个单列的值.(PHP 5.5+适用) 语法: array_column(array,column_k ...
- rocketmq的linux搭建环境
3.3. 上传解压[两台机器] # 上传 apache-rocketmq.tar.gz 文件至/usr/local # tar -zxvf apache-rocketmq.tar.gz -C /usr ...
- ubuntu下编译linux内核之前需要做哪些准备?
答: 安装必要的工具(笔者使用的ubuntu代号为bionic) sudo apt-get install -y bison flex
- 一些有意思的git
fs: https://github.com/psankar/simplefs https://github.com/gzc/isystem/blob/master/basic/Crash_Consi ...
- 运维之思科篇——NAT基础配置
一. NAT(网络地址转换) 1. 作用:通过将内部网络的私有IP地址翻译成全球唯一的公网IP地址,使内部网络可以连接到互联网等外部网络上. 2. 优点: 节省公有合法IP地址 处理地址重叠 增强灵活 ...
- 使用 certbot 自动给 nginx 加上 https
概述 目前,Let's Encrypt 可以算是最好用的 https 证书申请网站了吧.而 certbot 可以算是它的客户端,能够很方便的自动生成 https 证书.我把自己的使用经历记录下来,供以 ...
- FTP文件上传和下载(JAVA)
前文 1.使用FTP的方式进行文件的上传和下载(非SFTP) 2.本人手打,亲测,代码是最简单的,清晰易懂,需要的同学请结合自己的实际添加业务逻辑 2.第三方的jar包:import org.apac ...
- Using Android monkeyrunner from Eclipse, both in Windows and Linux!
This time I want to use English to make this article useful for all others in the world:) As you kno ...
- debian系统安装vsftpd服务端和ftp客户端
一.服务器安装和配置 1.安装vsftpd.(此处切换到su权限下了.其它用户请使用sudo权限,没有sudo权限的看前面的教程进行安装) apt-get install vsftpd 2.配置vsf ...
- Linux进程间通信(IPC)之信号量
[Linux]进程间通信(IPC)之信号量详解与测试用例 2017年03月22日 17:28:50 阅读数:2255 学习环境centos6.5 Linux内核2.6 进程间通信概述 1. 进程通信机 ...