-
1.前端请求代码
-
app.tsx
<input type="text" value={saveParams} onChange={(e) => setSaveParams(e.target.value.trim())} /> <button onClick={() => selectDiffInfo(saveParams)}>查询</button> </div> -
api.ts 页面
-
export function selectDiffInfo(value:any){
axios.get('/selecthotword',{
params:{
info:value
}
})
.then(res => {
console.log(res)
document.write(JSON.stringify(res.data))
})
}
-
node 获取参数返回数据
- http.ts 页面
app.get('/selecthotword',hotWord.selecthotword)-
hot-word.ts 页面
const selecthotword = (req: any, res: any) => { const hot_id = req.param('info') // 路径上传递的名称对应的值 const sql = `select * from hot_word where hot_id= ${hot_id}` connection.query(sql, (err: any, data: any) => { if (err) return console.log('SELECT hot_id ERROR -', err); res.send(data) console.log('----------------查询成功-------------------'); console.log(JSON.parse(JSON.stringify(data))); }) }
以上是带有参数的请求方式(get)