vue - mockjs

安装 npm install mockjs

在main.js 引入代码

import './serivce/mock.js'

在service/mock.js

const Mock = require('mockjs')
const Random = Mock.Random
const produceNewsData = function () {
  let articles = []
  for (let i=0;i<100;i++) {
    let newArticleObject = {
      title: Random.csentence(5,30),
      // thumbnail_pic_s: Random.dataImage('300*250', 'mock的图片'),
      author_name:Random.cname(),
      date:Random.date() + '' + Random.time()
    }
    articles.push(newArticleObject)
  }
  return {
    articles:articles
  }
}
Mock.mock('/news/api', 'post', produceNewsData)

在页面中使用

<template>
 <x-container>
   <slot-three @search = 'search'></slot-three>
 </x-container>
</template>

<script>
import SlotThree from '@/components/slot/SlotThree'
export default {
  name: 'slotPage',
  data () {
    return {
    }
  },
  components:{
    SlotThree
  },
  methods: {
    search(value){
    },
    axiosGetRole(){
      this.$ajax.post('/news/api').then(
        function(response){
          console.log(response)
        }
      ).catch(function(error){
        console.log(error)
      })
    }
  },
  created(){
    this.axiosGetRole()
  }
}
</script>

猜你喜欢

转载自blog.csdn.net/zhaofeiweb/article/details/86481111
今日推荐