1、安装mockjs
cnpm install mockjs --save-dev
2、在src目录下创建mock.js
import Mock from ‘mockjs‘; export default Mock.mock(‘http://vhen.com‘, { ‘name‘ : ‘@name‘, ‘age|1-100‘: 100, ‘color‘ : ‘@color‘ });
3、main.js 主入口引入mock.js
import ‘@/mock‘;
4、组件中调用
methods: { getData () { this.$http.get(‘http://vhen.com‘).then(res => { console.log(‘sdfdsfsf‘, res) }) } },
时间: 2024-10-13 18:50:22