【 错误总结 】axios请求本地 Json

结构目录

在这里插入图片描述
将模拟的数据存储在mock文件夹下 配置vue.config.js

const login = require('./src/mock/login.json')
const sort = require('./src/mock/sort.json')
const city = require('./src/mock/city.json')
const classify = require('./src/mock/classify.json')
const shop = require('./src/mock/shop.json')
const address = require('./src/mock/address.json')
const merchant = require('./src/mock/merchant.json')
const grade = require('./src/mock/grade.json')
module.exports = {devServer: {before: (app) => {app.get('/login', function (req, res, next) {res.json(login)})app.get('/sort', function (req, res, next) {res.json(sort)})app.get('/city', function (req, res, next) {res.json(city)})app.get('/classify', function (req, res, next) {res.json(classify)})app.get('/shop', function (req, res, next) {res.json(shop)})app.get('/address', function (req, res, next) {res.json(address)})app.get('/merchant', function (req, res, next) {res.json(merchant)})app.get('/grade', function (req, res, next) {res.json(grade)})}},// 关闭eslint检查lintOnSave: false,
};

请求数据

new Vue({methods:{getData() {this.$axios({url: "sort",method: "get",contentType: "application/json",dataType: "jsonp",}).then((data) => {this.filterData = data.data;}).catch((error) => error);},}
})