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

接上一节,咱们现在已经有了二个接口,分别是,

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 }
              });
  },

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_40943219/article/details/87206687