no message
Former-commit-id: 347253b910c9c8fd2c5a7d563e5c59dff6759ea3 Former-commit-id: 11a8486ada0efc2244927c648ee96511b06b27dd Former-commit-id: 2549cc4501bc5f40eccdba413c8ca458dae7a3b9
This commit is contained in:
35
static/markdownFiles/article/mock拦截ajax.md
Normal file
35
static/markdownFiles/article/mock拦截ajax.md
Normal file
@@ -0,0 +1,35 @@
|
||||
在 `src/mock/demo/001.js` 配置拦截返回的数据
|
||||
|
||||
```
|
||||
import Mock from 'mockjs'
|
||||
|
||||
Mock.mock('/api/demo/001', {
|
||||
'list|4-10': [{
|
||||
'id|+1': 1,
|
||||
'name': '@CNAME',
|
||||
'star|1-5': '★',
|
||||
'delFlag|1': [0, 1],
|
||||
'creatDate': '@DATE',
|
||||
'address': '@CITY',
|
||||
'zip': '@ZIP'
|
||||
}]
|
||||
})
|
||||
```
|
||||
|
||||
请求数据
|
||||
|
||||
```
|
||||
ajax () {
|
||||
this.$axios.get('/api/demo/001')
|
||||
.then(res => {
|
||||
this.table.columns = Object.keys(res.data.list[0]).map(e => ({
|
||||
label: e,
|
||||
prop: e
|
||||
}))
|
||||
this.table.data = res.data.list
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user