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. ...
随机推荐
- SpringMVC架构&组件&执行流程
SpringMVC架构: 组件: DIspatcherServlet:前端控制器.相当于mvc模式的c,是整个流程控制的中心,负责调用其他组件处理用户的请求,降低了组件之间的耦合性. HandlerM ...
- 01背包问题_回溯法&分支限界法
package 分支限界法; import java.util.LinkedList; import java.util.Scanner; /*01背包问题*/ public class ZOPack ...
- lnmp1.5安装swoole
php7.2安装swoole-4.0.1.tgz php5.6安装swoole-1.10.4.tgz wget http://pecl.php.net/get/swoole-4.0.1.tgz ...
- 修改Xshell字体大小和颜色
博客专区 > XManager的博客 > 博客详情 修改Xshell字体大小和颜色 XManager 发表于7个月前 分享到: 一键分享 QQ空间 微信 腾讯微博 新浪微博 QQ好友 有道 ...
- partialview 用法
using MvcApplication1.Models; @model MvcApplication1.Models.UserInfoModel @{ ViewBag.Title = &q ...
- 吴裕雄--天生自然JAVA数据库编程:JDBC操作步骤及数据库连接操作
public class ConnectionDemo01{ // 定义MySQL的数据库驱动程序 public static final String DBDRIVER = "org.gj ...
- linux下mysql允许远程连接
1. MySql安装教程 https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html 默认情况下mysq的 roo ...
- postgres 删除外部表
drop external table if exists tableName;
- OpenResty 实现项目的灰度发布
1.安装 openresty 依赖模块: [root@Centos opt]# yum -y install pcre-devel openssl openssl-devel postgresql-d ...
- vs2010编译C++ 对象的使用
// CTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using names ...