菜鸟之如何让项目跑起来(适合小白看,不是小白的不要进来看了,浪费时间)

今天研究了如何让vue 项目跑起来,简单实现调通后端的接口
实现步骤:
1.新建一个项目 vue create xxx(项目名字,自定义即可
2.项目跑起来,安装axios npm install axios
3.引入axios,配置axios 相关的参数(如baseURL等)
下面重点介绍实现方法三多种方式
方法一:创建vue.config.js文件,内容如下:
module.exports = {
devServer: {
proxy: ‘http://xxxxx.xxx:88’ // 后端地址
}
}
在页面中,axios是这种用的
axios.post(’/test’, {
name:’ zhangsan’,
pwd:‘123456’
})
.then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});

方法二:在页面中直接完整的地址
axios.post(‘http://xxxxx.xxx:88/test’, {
name:’ zhangsan’,
pwd:‘123456’
})
.then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
方法三: 通过向 axios 传递相关配置来创建请求
axios({
method: ‘post’,
url: ‘http://xxxxx.xxx:88/test’,
data:{
name:’ zhangsan’,
pwd:‘123456’
}
})
.then(function (response) {
alert(“success”)
console.log(response);
}).catch(function (error) {
console.log(error);
});

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值