Vue-cli3.3版本下数据模拟
废话不多说直接上图上代码
文件目录如下

配置代码如下
const DATA = require("./mock/data.json");
const seller = DATA.seller;
const goods = DATA.goods;
const ratings = DATA.ratings;
module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? '/production-sub-path/'
: '/',
devServer: {
port: 8080,
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
before(app) {
app.get("/api/seller", (req, res) => {
res.json({
errno:0,
seller: seller,
});
});
app.get('/api/goods', function(req, res) {
res.json({
errno: 0,
data: goods
})
});
app.get('/api/ratings', function(req, res) {
res.json({
errno: 0,
data: ratings
})
});
}
}
}
APP.VUE中获取数据方法
export default { name: 'app', data() { return { seller: {} } }, mounted () { this.axios.get(URL) .then((response) => { console.log(response.data.seller + '-' + response.status); if(response.data.errno === ERR_OK){ this.seller = response.data.seller; console.log(this.seller); } }) .catch(function (error) { console.log(error); }); }, components: { 'v-header': Header } }
目前就是不知道为啥获取到非要用response.data才能获取到。希望大佬能给个指示

浙公网安备 33010602011771号