npm install or cnpm install
npm run serve
npm run build
npm run lint
npm run test:unit
- Node >= 8.11.x
- webpack >= 4.x
- vue >= 2.x
- stylus
- pug
import http from '@/commons/http'
http.get('/url').then((response) => {
console.log(response.data)
});
http.post('/url', {
param: param
}).then((response) => {
console.log(response.data)
})
这里有坑,get方法最多传两个参数,post方法最多传三个参数,其实统一写法会好理解一些,如:
http({
method: 'GET', // GET或者POST
apiType: '', //接口类型
url: '/user/12345', // 请求地址
data: {
// 调用post接口传参,params中的参数不被接收
},
params: {
// 调用get接口传参,data中参数不被接收
},
mask:, // 设置为false,通过ajax请求接口时,菊花消失
json:, // 设置为true,设置headers[ 'Content-Type' ] = 'application/json; charset=UTF-8'
token:, // 设置为false,调用后台接口将不自动增加token
}).then((response) => {
console.log(response.data)
})
客户端的ajax公共方法是在axios的基础上包裹了一层,(点击查看 axios相关的参数配置),新增参数如下:
- apiType: 'DEMO', //接口类型,对多个渠道接口进行统一配置,详情见src/conf/api.js
- mask:设置为false,通过ajax请求接口时,菊花消失(* ̄□ ̄)
- json:设置为true,headers[ 'Content-Type' ] = 'application/json; charset=UTF-8'
- token:设置为false,调用后台接口将不自动增加token
import qs from 'querystring' // 格式化请求参数
qs.stringify({a:1, b:2})) // 输出 a=1&b=2
qs.parse(window.location.search) // 输出 { x:1, y:1 }
import moment from 'moment'
moment().format('YYYY-MM-DD') // 格式化时间
moment().add(1, 'days') // 增加一天时间
在stores目录下的index.js中的state对象里面预先定义好你需要返回的字段属性名
子组件需要把该字段加入到watch中去监听它的值变化,监听得到了数据值之后在处理
如果直接操作数组下标改变数据无法映射到页面,那就使用数组的splice方法操作数组内容