Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mock 添加新配置项不生效 #62

Open
chazex opened this issue Sep 25, 2019 · 0 comments
Open

mock 添加新配置项不生效 #62

chazex opened this issue Sep 25, 2019 · 0 comments

Comments

@chazex
Copy link

chazex commented Sep 25, 2019

我这边模拟article,自己建立了一个新的mock,名字为record,但是重启后,并不生效,提示404.还有什么地方需要修改吗?

api/record.js
`import request from '@/utils/request'

export function fetchList(query) {
return request({
url: '/record/list',
method: 'get',
params: query
})
}`

mock/index/js
`
import Mock from 'mockjs'
import { param2Obj } from '../src/utils'

import user from './user'
import role from './role'
import article from './article'
import record from "./record";
import search from './remote-search'
import test from './test'

const mocks = [
...user,
...role,
...article,
...search,
...record,
...test,
]
`

mock/record.js
`import Mock from 'mockjs'

const List = []
const count = 100

const baseContent = '

I am testing data, I am testing data.

'
const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'

for (let i = 0; i < count; i++) {
List.push(Mock.mock({
id: '@increment',
timestamp: +Mock.Random.date('T'),
author: '@FIRST',
reviewer: '@FIRST',
title: '@title(5, 10)',
content_short: 'mock data',
content: baseContent,
forecast: '@float(0, 100, 2, 2)',
importance: '@integer(1, 3)',
'type|1': ['CN', 'US', 'JP', 'EU'],
'status|1': ['published', 'draft', 'deleted'],
display_time: '@datetime',
comment_disabled: true,
pageviews: '@integer(300, 5000)',
image_uri,
platforms: ['a-platform']
}))
}

export default [
{
url: '/record/list',
type: 'get',
response: config => {
const { importance, type, title, page = 1, limit = 20, sort } = config.query

  let mockList = List.filter(item => {
    if (importance && item.importance !== +importance) return false
    if (type && item.type !== type) return false
    if (title && item.title.indexOf(title) < 0) return false
    return true
  })

  if (sort === '-id') {
    mockList = mockList.reverse()
  }

  const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

  return {
    code: 20000,
    data: {
      total: mockList.length,
      items: pageList
    }
  }
}

},
]
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant