diff --git a/src/App.vue b/src/App.vue index 591a031..5c86d2d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,26 +1,17 @@ +// App.vue + - - diff --git a/src/main.js b/src/main.js index 01433bc..1417c3f 100644 --- a/src/main.js +++ b/src/main.js @@ -1,4 +1,5 @@ import { createApp } from 'vue' import App from './App.vue' +require('./mock') createApp(App).mount('#app') diff --git a/src/mock.js b/src/mock.js new file mode 100644 index 0000000..26cf8b4 --- /dev/null +++ b/src/mock.js @@ -0,0 +1,21 @@ +// mock.js + +// 引入mockjs +const Mock = require('mockjs') +// 获取 mock.Random 对象 +const Random = Mock.Random +// mock新闻数据,包括新闻标题title、内容content、创建时间createdTime +const produceNewsData = function () { + let newsList = [] + for (let i = 0; i < 20; i++) { + let newNewsObject = { + title: Random.ctitle(), // Random.ctitle( min, max ) 随机产生一个中文标题,长度默认在3-7之间 + content: Random.cparagraph(), // Random.cparagraph(min, max) 随机生成一个中文段落,段落里的句子个数默认3-7个 + createdTime: Random.date() // Random.date()指示生成的日期字符串的格式,默认为yyyy-MM-dd; + } + newsList.push(newNewsObject) + } + return newsList +} +// 请求该url,就可以返回newsList +Mock.mock('/mock/news', produceNewsData) // 后面讲这个api的使用细节