【笔记】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可以省略 ...
随机推荐
- LeetCode 216. 组合总和 III(Combination Sum III)
题目描述 找出所有相加之和为 n 的 k 个数的组合.组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字. 说明: 所有数字都是正整数. 解集不能包含重复的组合. 示例 1: 输入 ...
- 尚硅谷Docker---1、docker杂记
尚硅谷Docker---1.docker杂记 一.总结 一句话总结: ~ php用的homestead就相当于docker,javaee一般都是用docker,php也可以用docker ~ dock ...
- .NET Assembly File Format
https://docs.microsoft.com/en-us/dotnet/standard/assembly/file-format .NET defines a binary file for ...
- vmware安装centos虚拟机,没有ip地址
如果centos没有ip地址,就不能通过xshell等工具进行连接,且在上面部署的项目,外部也不能正常访问 两种方式可以解决 第一种,在安装的时候,在INSTALLATION SUMMARY界面的SY ...
- LC 358. Rearrange String k Distance Apart
Given a non-empty string s and an integer k, rearrange the string such that the same characters are ...
- [Python]切换工作目录|python将目录切换为脚本所在目录
Python使用os.chdir命令切换python工作目录 代码示例: In []: import os In []: os.system("pwd") /home/wangju ...
- Spring RedisTemplate常用方法(List,Hash)
@Autowired private RedisTemplate<String, String> redisTemplate; @Override public List<Strin ...
- pycharm设置背景颜色
https://jingyan.baidu.com/article/9faa7231f88570473c28cb88.html
- H5中调起微信这么实现,如果未安装则提示未安装
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- css中元素定位
在html中网页可以看成一个立体的空间,一个完整的页面是由很多个页面堆积形成的,如下图所示 CSS中Position属性有四个可选值,它们分别是:static.absolute.fixed.relat ...