vue+node全栈移动商城【6】-node接口配置文件

9次阅读

共计 545 个字符,预计需要花费 2 分钟才能阅读完成。

接上一节,咱们现在已经有了二个接口,分别是,
app.get(‘/node_a’

app.get(‘/node_a’
以后还会有更多的接口,那么有必要在一个单独的地方来统一管理所有的接口。
在 src 目录下新建一个文件:api_dev.js,代码如下:
const port = 5678;
const BASEURL = ‘http://localhost:’ + port;

const API_LIST = {
// 查询条件
node_a : BASEURL + ‘/node_a’,
// 查询结果
node_b : BASEURL + ‘/node_b’
}

module.exports = API_LIST
这样就把所有的接口都放在 API_LIST 对象中,并向外导出,然后在需要使用的地方,直接 import 导入之后,就对象. 属性的方式就可以使用了。就像下面这样,
<script>
import axios from ‘axios’
import API_LIST from ‘@/APIList.config’


methods:{
sendBtn(){
let _val = this.$refs.inputRef.value;
// console.log(_val)

axios.get(API_LIST.node_a ,{
params:{v_data : _val}
});
},

正文完
 0