Indicator.open('加载中...') return axios(option).then(v=>{ let data = v.data.data return new Promise((res,rej)=>{ if(!v) return rej() Indicator.close() res(data) }) }) } }
后端接收前端请求里的数据参数(使用express框架):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
var express = require('express'); var router = express.Router(); // 引入连接数据库 var connection = require('../db/sql.js') // 查询搜索接口 router.get('/api/goods/shopList',function(req,res,next){ let searchName= req.query.searchName // 模糊查询 connection.query('select * from goods_list where name like "%'+searchName+'%"',function(err,results){ console.log(err); // 返回匹配到的数据给前端 res.send({ code:0, data:results }) }) })
连接数据库:
1 2 3 4 5 6 7 8
const mysql = require('mysql') let connection = mysql.createConnection({ host:'localhost', user:'root', password:'admin123', database:'vue-tea-store' }) module.exports = connection;