1.在common文件夹创建httpApi.js文件,内容如下
var getNewsDetail ='/api/v1/news/getNewsDetail';
var getNewsList ='/api/v1/news/getNewsList';
export default {
getNewsDetail:getNewsDetail,//资讯详情
getNewsList:getNewsList,//资讯列表
};
2.main.js 引入
import Vue from 'vue'
import App from './App'
import httpApi from './common/httpApi';
Vue.config.productionTip = false
App.mpType = 'app'
Vue.prototype.$httpApi = httpApi//赋值到vue里面
const app = new Vue({
...App
})
app.$mount()
3.在单个页面调用变量
this.$httpApi.getNewsList
很实用