Vue2.0+Node.js+MongoDB全栈打造商城系统
vue.js +axios mock数据
在main.js中
import axios from 'axios' Vue.prototype.$ajax = axios
webpack.dev.conf.js中
const express = require('express') const app = express() const goodsData = require('./../goods.json')
在devServer中
before(app) {
app.get('/goods',(req,res) => {
res.json(goodsData)
})
}
在GoodsList组件中
data () { return { goods: [] } }, created () { this.$ajax.get('/goods').then((res) => { const data = res.data this.goods = data.result }) },