1.先创建一个Global.vue文件
const user_id='';
const baseURL = 'http://118.25.10.***' //服务器IP
export default
{
user_id,//用户id
baseURL,//服务器地址
}
2.在main.js引入
import axios from 'axios'
import VueAxios from 'vue-axios'``
import global_ from './components/public/Global'//引用文件
Vue.prototype.GLOBAL = global_//挂载到Vue实例上面
axios.defaults.baseURL = global_.BASE_URL;
Vue.use(VueAxios, axios)
3.
1.2那样就可以*.vue script代码中就可以使用了
countDown() {
const self = this;
clock = window.setInterval(() => {
self.total--;
self.content = self.total + 's后重新发送';
}, 1000);
self.isDisable = true;
let data = {
"c_tel": self.c_tel,
}
axios({
method: 'post',
url: self.GLOBAL.baseURL + '/index.php/user/client/sendsms',
data: Qs.stringify(data),
}).then(function(response) {
if(response.data.code == '200') {
self.res = response.data.data;
}
})
.catch(function(error) {
console.log(error);
});
},
4.如果有跨域问
在请求的时候加上axios.defaults.withCredentials = true;