no message
Former-commit-id: 7f236976ce87ddabb1eddf615ebaa57e5b6347f8 Former-commit-id: 1eecee8e0901e62b51912a596488f9109e54a663 Former-commit-id: 37a6d948534b3897886ad2472901979282ffce28
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