【笔记】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可以省略 ...
随机推荐
- conda程序使用
conda -c 参数 使用清华镜像时不要使用-c 参数.-c参数是anaconda的默认channel. 查询安装源中某个包的可以安装的版本 conda search -f package_name ...
- tp5 模型中 关联查询(省去了foreach写法)
1.控制器中 $list = Userlawsbook::where($where)->with('lawsbook')->paginate(7); // 此处查出来为数组对象 dump ...
- .NET Assembly File Format
https://docs.microsoft.com/en-us/dotnet/standard/assembly/file-format .NET defines a binary file for ...
- java 直接内存
android 内存结构 : dalvik(jvm)内存---navtive men 两部分. 这个概念相信有经验的开发人员都会知道. java虚拟机分配到的内存是有限的,根据手机不同,大小不一,但也 ...
- 发布Rest风格的WebService的SpringBoot极简例子
JDK:1.8.0_212 IDE:STS4(Spring Tool Suit4 Version: 4.3.2.RELEASE) 工程下载:https://files.cnblogs.com/file ...
- n个骰子可能的点数和
让后面的点数比前面的大 package touzi; public class Touzi { public static void main(String[] args) { // TODO Aut ...
- CentOS linux7 重置root密码
1.启动linux,进入grub,就是选择系统界面,选中系统按e进入编辑界面 2.找到linux16那一行,在末尾加上init=/bin/sh.按Ctrl+x,使用单用户模式启动4.mount -o ...
- 在Latex中插入Python代码
这里指的插入是指最终能在生成的pdf中显示高亮的Python代码. 在Latex中插入Python代码,需要一个第三发的宏包pythonhighlight: https://github.com/ol ...
- springboot2.0双数据源配置
题记:由于项目中不只是用一个数据库,所以记下以免忘记. 1.首先展示目录结构 2.pom配置文件 <?xml version="1.0" encoding="UTF ...
- 监控系统-PMM
Percona Monitoring and Management (PMM)是一款开源的用于管理和监控MySQL和MongoDB性能的开源平台 通过PMM客户端收集到的DB监控数据用第三方软件Gra ...