vuejs 使用axios 使用方法
2018-03-04 00:00
281 查看
引入注册全局
全局使用,url必须全写,否者404.
create 构建一个 axios实例来使用,也可以直接$http.get 使用 $http 是在main.js中注册的axios
参考
https://github.com/axios/axios
GET 代码
POST 代码
// main.js 引入 import axios from 'axios' // 插件。 Vue.prototype.$http = axios
全局使用,url必须全写,否者404.
create 构建一个 axios实例来使用,也可以直接$http.get 使用 $http 是在main.js中注册的axios
参考
https://github.com/axios/axios
GET 代码
var instance = this.$http.create({ headers: {'content-type': 'application/x-www-form-urlencoded'} }) instance.get('http://127.0.0.1:8082/index/Ajaxget') .then(function (response) { console.log(response) }) .catch(function (error) { console.log(error) }) },
POST 代码
export default { name: 'App', // 定义数据对象 data () { return { user: '', password: '', ifLogin: true } }, // 定义事件对象 methods methods: { // 登录 onLogin: function () { var there = this var instance = this.$http.create({ headers: {'content-type': 'application/x-www-form-urlencoded'} }) instance.post('https://easy-mock.com/mock/5aa916df93041f109b6e8fba/example/login/login', { firstName: there.user, lastName: there.password }) .then(function (response) { console.log(response.data.data.iflogin) console.log(there.ifLogin) there.ifLogin = !response.data.data.iflogin }) .catch(function (error) { console.log(error) }) } }
相关文章推荐
- vuejs使用axios异步访问时用get和post的方法
- 基于vue-cli的vue项目之axios的使用5--axios方法发送请求
- vuejs中vue-resource或使用axios发送请求及解决跨域问题
- vue-cli的axios使用方法,get、post请求的跨域问题解决
- axios 详细使用方法 及跨域请求(反向代理)的处理
- 使用async await 封装 axios的方法
- vue 2.0中使用axios遇到问题的解决方法
- vue-resource和vue-axios的简单使用方法
- vue-cli 使用axios的操作方法及整合axios的多种方法
- vue项目使用axios发送请求让ajax请求头部携带cookie的方法
- vue中使用axios post上传头像/图片并实时显示到页面的方法
- axios使用拦截器统一处理所有的http请求的方法
- 在不使用全部vuejs框架,只在html中引用vue.js时,在main.js中调用其他js方法
- 在Vue中使用axios请求拦截的实现方法
- 在 Vue 结合 Axios 使用过程 中 post 方法,后台无法接受到数据问题
- axios 详细使用方法 及跨域请求(反向代理)的处理
- 在axios中使用params传参的时候传入数组的方法
- 在Vue组件化中利用axios处理ajax请求的使用方法
- 使用axios上传照片的方法
- vue axios数据请求及vue中使用axios的方法