vue全家桶router、vuex、axios
main.js
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './vuex'
import Axios from 'axios' Vue.prototype.$axios=Axios Axios.defaults.baseURL="http://www.wwtliu.com" Vue.config.productionTip = false new Vue({
el: '#app',
router,
store,
components: {App},
template: '<App/>'
})
一、router
import Vue from 'vue'
import Router from 'vue-router'
import all from '@/components/all' Vue.use(Router) const router = new Router({
mode: "history",
routes: [
{
path: '/',
redirect: "/all"
},
{
path: '/all',
component: all
},
{
path: '/all/:data',
component: all
}
]
}) export default router;
<router-link to="/all" tag="li">全部</router-link> <router-view/>
this.$router.push({name:'',path:'',query:{data:''},params:{data:''}})
this.$route.query.data
this.$route.params.data
路由守卫:
beforeRouteEnter(to,from,next){
if(false){
next();
}else{
next("/login");
}
}
router.beforeEach((to,from,next)=>{
if(to.path=="/info" && false){
next()
}else{
next("/login")
}
})
二、vuex
import Vue from "vue"
import Vuex from "vuex" Vue.use(Vuex) const store = new Vuex.Store({
state: {
list:[]
},
mutations: {
add(state,arg){
state.list.push(arg);
}
},
getters:{
activelist(state){
return state.list.filter(item=>item.tasksty)
}
},
actions:{
//异步处理
saveDataAction(arg_store){
arg_store.commit('add','data_data_data');
}
}
}) export default store;
this.$store.dispatch("saveDataAction");
<input type="text" placeholder="你打算做什么?" @keyup.enter="modelvalue">
methods:{
modelvalue(ev){
this.$store.commit("add",{taskval:ev.target.value,tasksty:false});
}
}
<li v-for="li in list"></li>
<li v-for="li in activelist"></li> import {mapState,mapGetters} from "vuex"
computed:{
...mapState(["list"]),
...mapGetters(["activelist"])
}
三、axios
this.$axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
}, {
headers: {
'token': ''
},
responseType: 'blob'
}).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
this.$axios.get('/user', {
headers: {
'token': ''
},
responseType: 'blob',
params:{
firstName: 'Fred',
lastName: 'Flintstone'
}
}).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
this.$axios.interceptors.request.use(req => {
return req;
},err => {
return Promise.reject(err);
})
this.$axios.interceptors.response.use(res => {
return res;
},err => {
return Promise.reject(err);
})
vue全家桶router、vuex、axios的更多相关文章
- vue 项目实战 (vue全家桶之--- vuex)
老规矩先安装 npm install vuex --save 在看下面内容之前 你应该大概的看了一边vuex官方的文档对vuex有个大概对了解 首先 vuex 是什么? vuex 是属于vue中的什么 ...
- Vue全家桶之——Vuex
Vuex 是什么? Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化.Vuex 也集成到 Vu ...
- vue学习(十二)vue全家桶 Vue-router&Vuex
一 vue-router的安装 二 vue-router的基本使用 三 命名路由 四 动态路由的匹配和路由组件的复用 一 vue-router的安装 NPM npm install vue-route ...
- 【实战】Vue全家桶(vue + axios + vue-router + vuex)搭建移动端H5项目
使用Vue全家桶开发移动端页面. 本博文默认已安装node.js. github链接 一.准备工作 安装vue npm install vue 安装脚手架vue-cli npm install -g ...
- vue全家桶+axios+jsonp+es6 仿肤君试用小程序
vue全家桶+axios+jsonp+es6 仿肤君试用小程序 把自己写的一个小程序项目用vue来实现的,代码里面有一些注释,主要使用了vue-cli,vue,vuex,vue-router,axoi ...
- 从零开始系列之vue全家桶(3)安装使用vuex
什么是vuex? vuex:Vue提供的状态管理工具,用于同一管理我们项目中各种数据的交互和重用,存储我们需要用到数据对象. 即data中属性同时有一个或几个组件同时使用,就是data中共用的属性. ...
- 用 Vue 全家桶二次开发 V2EX 社区
一.开发背景 为了全面的熟悉Vue+Vue-router+Vuex+axios技术栈,结合V2EX的开放API开发了这个简洁版的V2EX. 在线预览 (为了实现跨域,直接npm run dev部署的, ...
- 使用vue全家桶制作博客网站
前面的话 笔者在做一个完整的博客上线项目,包括前台.后台.后端接口和服务器配置.本文将详细介绍使用vue全家桶制作的博客网站 概述 该项目是基于vue全家桶(vue.vue-router.vuex.v ...
- 转载: 使用vue全家桶制作博客网站 HTML5 移动网站制作的好教程
使用vue全家桶制作博客网站 前面的话 笔者在做一个完整的博客上线项目,包括前台.后台.后端接口和服务器配置.本文将详细介绍使用vue全家桶制作的博客网站 概述 该项目是基于vue全家桶(vue. ...
随机推荐
- Scrapy 常用的shell执行命令
1.在任意系统下,可以使用 pip 安装 Scrapy pip install scrapy/ 确认安装成功 >>> import scrapy >>> scrap ...
- 如何让图片在div里左右居中,上下居中
如何让图片在div里左右居中,上下居中 转载▼ 1.要想让图片左右对齐,我们可以在div里写入"style:text-align:center;"代码来实现. 2.要想使图片居 ...
- P1481 魔族密码(LIS变形)
题目描述(题目链接:https://www.luogu.org/problem/P1481) 风之子刚走进他的考场,就…… 花花:当当当当~~偶是魅力女皇——花花!!^^(华丽出场,礼炮,鲜花) 风之 ...
- 「NOIP2016」愤怒的小鸟
传送门 Luogu 解题思路 首先这个数据范围十分之小啊. 我们考虑预处理出所有可以带来贡献的抛物线 三点确定一条抛物线都会噻 然后把每条抛物线可以覆盖的点状压起来,然后状压DP随便转移就好了. 有一 ...
- 「CF650E」Clockwork Bomb
传送门 Luogu 解题思路 显然对于两棵树共有的边,我们不会动它. 考虑第二颗树中有和第一棵树不同的边怎么处理. 我们设 \(fa_1[u],fa_2[u]\) 分别代表 \(u\) 在两棵树中的父 ...
- 使用Spring Cloud Gateway保护反应式微服务(二)
抽丝剥茧,细说架构那些事——[优锐课] 接着上篇文章:使用Spring Cloud Gateway保护反应式微服务(一) 我们继续~ 将Spring Cloud Gateway与反应式微服务一起使用 ...
- Lesson 3 Matterhorn man
What was the main objective of early mountain climbers? Morden alpinists try to climb mountains by a ...
- 【转】深入分析JAVA IO(BIO、NIO、AIO)
IO的基本常识 1.同步 用户进程触发IO操作并等待或者轮询的去查看IO操作是否完成 2.异步 用户触发IO操作以后,可以干别的事,IO操作完成以后再通知当前线程继续处理 3.阻塞 当一个线程调用 r ...
- JDBC Connection Configuration配置正确,提示Error preloading the connection pool
JDBC Connection Configuration配置正确,提示Error preloading the connection pool JDBC 请求报错,提示: 因为之前执行是正确的,这次 ...
- JuJu团队1月3号工作汇报
JuJu团队1月3号工作汇报 JuJu Scrum 团队成员 今日工作 剩余任务 困难 飞飞 测试dataloader 将model嵌入GUI 无 婷婷 调试代码 提升acc 无 恩升 -- 写p ...