- Published on
vue-element-admin
- Authors
- Name
- Lucas Xu
- @xianminx
axios
Promise based HTTP client for the browser and node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hello_axios() { | |
const axios = require('axios'); | |
axios.get('https://cityapi.opentown.cn/events/5b3a2aed66db7502c0a2760x').then(function (response) { | |
console.log(response); | |
}).catch(function (error) { | |
console.log(error); | |
}).then(function () { | |
console.log('always executed') | |
}); | |
// Make a request for a user with a given ID | |
axios.get('/user?ID=12345') | |
.then(function (response) { | |
// handle success | |
console.log(response); | |
}) | |
.catch(function (error) { | |
// handle error | |
console.log(error); | |
}) | |
.then(function () { | |
// always executed | |
}); | |
// Optionally the request above could also be done as | |
axios.get('/user', { | |
params: { | |
ID: 12345 | |
} | |
}) | |
.then(function (response) { | |
console.log(response); | |
}) | |
.catch(function (error) { | |
console.log(error); | |
}) | |
.then(function () { | |
// always executed | |
}); | |
// Want to use async/await? Add the `async` keyword to your outer function/method. | |
async function getUser() { | |
try { | |
const response = await axios.get('/user?ID=12345'); | |
console.log(response); | |
} catch (error) { | |
console.error(error); | |
} | |
} | |
function getUserAccount() { | |
return axios.get('/user/12345'); | |
} | |
function getUserPermissions() { | |
return axios.get('/user/12345/permissions'); | |
} | |
axios.all([getUserAccount(), getUserPermissions()]) | |
.then(axios.spread(function (acct, perms) { | |
// Both requests are now complete | |
})); | |
} |
mock.js
create project and download deps.
vue create hello_mockjs
cd hello_mockjs
npm install mockjs
npm run serve
- 数据模板定义规范 DTD
'name|rule': value
random
Random is a useful nodejs commandline / library for generating random objects, like url, email, etc.
npm install random -g
➜ hello_mockjs git:(master) ✗ random
Usage: random [options] [command]
Options:
-V, --version output the version number
-h, --help output usage information
Commands:
boolean Random.boolean( min, max, cur )
bool Random.bool( min, max, cur )
natural Random.natural( min, max )
integer Random.integer( min, max )
int Random.int( min, max )
float Random.float( min, max, dmin, dmax )
character Random.character( pool )
char Random.char( pool )
string Random.string( pool, min, max )
str Random.str()
range Random.range( start, stop, step )
date Random.date( format )
time Random.time( format )
datetime Random.datetime( format )
now Random.now( unit, format )
image Random.image( size, background, foreground, format, text )
img Random.img()
color Random.color( name )
hex Random.hex()
rgb Random.rgb()
rgba Random.rgba()
hsl Random.hsl()
paragraph Random.paragraph( min, max )
cparagraph Random.cparagraph( min, max )
sentence Random.sentence( min, max )
csentence Random.csentence( min, max )
word Random.word( min, max )
cword Random.cword( pool, min, max )
title Random.title( min, max )
ctitle Random.ctitle( min, max )
first Random.first()
last Random.last()
name Random.name( middle )
cfirst Random.cfirst()
clast Random.clast()
cname Random.cname()
url Random.url( protocol, host )
protocol Random.protocol()
domain Random.domain( tld )
tld Random.tld()
email Random.email( domain )
ip Random.ip()
region Random.region()
province Random.province()
city Random.city( prefix )
county Random.county( prefix )
zip Random.zip( len )
d4 Random.d4()
d6 Random.d6()
d8 Random.d8()
d12 Random.d12()
d20 Random.d20()
d100 Random.d100()
guid Random.guid()
uuid Random.uuid()
id Random.id()
Examples:
$ random date yyyy-MM-dd
$ random time HH:mm:ss
ES2015+
vuex
每一个 Vuex 应用的核心就是 store(仓库)。“store”基本上就是一个容器,它包含着你的应用中大部分的状态 (state)。
reactive in store state vars.
commit mutation
vue-router
Questions
import request from '@/utils/request'
what is @?requests interceptor 中 set login token
response interceptor 中验证 response 错误
sidebar: state => state.app.sidebar,
store
getters
const store = new Vuex.Store({ modules: { app, user, }, getters, }) export default store
export function
router
{ path: '/', component: Layout, redirect: '/dashboard', name: 'Dashboard', hidden: true, children: [{ path: 'dashboard', component: () => import('@/views/dashboard/index') }] },
vuex
getters
mapGetters
mutations