搜索
查看
编辑修改
首页
UNITY
NODEJS
PYTHON
AI
GIT
PHP
GO
CEF3
JAVA
HTML
CSS
搜索
笔触狂放9
这个屌丝很懒,什么也没留下!
关注作者
热门标签
jquery
HTML
CSS
PHP
ASP
PYTHON
GO
AI
C
C++
C#
PHOTOSHOP
UNITY
iOS
android
vue
xml
爬虫
SEO
LINUX
WINDOWS
JAVA
MFC
CEF3
CAD
NODEJS
GIT
Pyppeteer
article
热门文章
1
idea 相关问题处理_idea 一直analyzing
2
校招秋招BOSS话术沟通话术(结尾有示例 Java)
3
104、基于STM32单片机两轮自动平衡小车蓝牙APP控制 加超声波避障和跟随模式设计OLED屏显示(程序+原理图+PCB源文件+硬件芯片资料等)_蓝牙小车pcb
4
“前缀和”专题篇一
5
安全服务资质认证_萌新三问:个人有哪些安全证书?企业有哪些安全资质?跟投标有什么关系?_新手攻防自学_中国通信企业协会通信网络安全专业委员
6
针对amlogicAB升级-编译流程优化_make otapackage
7
python 下载并离线安装第三方库_python第三方库离线下载
8
数据采集网关:蓝牙网关在数据采集中的卓越能力
9
心法利器[107] onnx和tensorRT的bert加速方案记录
10
2021年嵌入式面试题汇总(最新经典)
当前位置:
article
> 正文
vue2.0之axios使用详解(二)
作者:笔触狂放9 | 2024-08-19 08:36:40
赞
踩
vue2.0之axios使用详解(二)
发了vue2.0之axios使用详解(一)后,有朋友问如何在实际项目中使用,下面把我平常用的两种方法分享下,自己在实际项目中总结的方法,有不好的地方还请指正,共同提高,谢谢!
[javascript]
view plain
copy
方法一:直接在.vue文件中引入使用
在.vue文件中使用
<script>
import
axios from
'axios'
;
export
default
{
name:
'news'
,
data () {
return
{
}
},
methods: {
getNewsFn(){
axios.get(
this
.dataURL +
'/getNews'
).then((news) => {
this
.news = news.data;
}
).
catch
((err) => {
console.log(err);
}
);
}
}
}
</script>
方法二:注册为全局的函数
首先在main.js文件中引入
import
axios from
'../node_modules/axios'
;
Vue.prototype.axios = axios;
new
Vue({
el:
'#app'
,
router,
store,
axios,
echarts,
template:
'<App/>'
,
components: { App }
});
其次在.vue文件中使用
defaultData(){
let _this =
this
;
_this.axios.get(
'http://'
+ _this.$store.state.defaultHttp +
'?action_type=comp_news&comp_id='
+ _this.$store.state.compValue +
'&offset=0&len='
+ _this.pageNum, {}, {
headers: {}
}).then(
function
(response) {
}).
catch
(
function
(response) {
console.log(response);
});
}
声明:
本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:
https://www.wpsshop.cn/w/笔触狂放9/article/detail/1001537
推荐阅读
article
vue2
-
axios
二次
封装_
vue2
axios
二次
封装...
【代码】
vue2
-
axios
二次
封装。_
vue2
axios
二次
封装
vue2
axios
二次
封装 ...
赞
踩
article
vue2
封装网络
请求
axios
_
vue2
封装
axios
请求
...
这篇博客介绍了如何在项目中配置和封装
axios
以适应不同环境的API
请求
。首先通过npm安装
axios
,然后创建一个co...
赞
踩
article
Vue2
-
axios
三层
封装
_
vue2
axios
封装
...
文章介绍了如何对
axios
进行三层
封装
:第一层增强
axios
,设置公共基础URL,添加请求和响应拦截器;第二层
封装
项目中...
赞
踩
article
vue2
axios
封装_
vue2
中封装
axios
...
【代码】
vue2
axios
封装。_
vue2
中封装
axios
vue2
中封装
axios
i...
赞
踩
article
vue
2
.0
_
在
vue
中
axios
请求
的
封装
和使用
_
vue
2
axios
封装
完整实例...
本文介绍了在Vue2.0项目中如何进行
axios
请求
的
封装
,包括在src/utils/request.js中
封装
axio...
赞
踩
article
vue2
使用
axios
_
vue2
axios
...
本文详细介绍了如何在Vue2项目中安装、配置和使用Axios进行HTTP请求,包括全局设置、基本操作、拦截器的应用以及如...
赞
踩
article
vue2.0
中引入和
使用
axios
...
vue2.0
中引入和
使用
axios
vue2.0
中引入和
使用
axios
...
赞
踩
article
vue2.0
之
axios
使用
详解_
vue2.0
axios
...
axios
基于 Promise 的 HTTP 请求客户端,可同时在浏览器和 node.js 中
使用
功能特性在浏览器中发送...
赞
踩
article
Vue2.0
教程
(四)
axios
学习
_
vue
axios
菜鸟
教程
...
axios
1.1
axios
概念
axios
是一个专注于网络请求的库!
axios
(发音:艾克笑死) 是前端圈最火的、专注于...
赞
踩
article
Vue2.0
之
axios
使用_
vue2.0
amis
...
一、功能在浏览器中发送 XMLHttpRequests 请求 在 node.js 中发送 http请求 支持 Promi...
赞
踩
article
Vue2.0
学习——
axios
用法详解
_
vue2.0
axios
...
原来vue更新到2.0之后,尤大就宣告不再对vue-resource更新,而是推荐的
axios
。在github上,415...
赞
踩
article
「
VUE
架构」
VUE
2.0
Axios
深入浅出
_
vue2
支持
axio
版本...
本文详细介绍了Vue2.0中使用
Axios
进行API调用的配置过程,包括从vue1.0升级时遇到的'app.get is...
赞
踩
article
Vue
ElementUI
操作 和
Axios
使用_
vue2.0
配置
element
-
ui
+ax...
Vue
ElementUI
和
Axios
内容分享。_
vue2.0
配置
element
-
ui
+
axios
vue2....
赞
踩
article
VUE2.0
中
axios
的
使用
_
vue2.0
axios
用法...
1首先 npm install
axios
2安装其他插件的时候,可以直接在 main.js 中引入并
使用
Vue.use...
赞
踩
article
vue2
引入
Element
UI和
Axios
_
vue2
.0 安装
element
+
axios
...
在项目中控制台输入npm install
element
-ui --save命令进行安装,项目中引进
Element
UI...
赞
踩
article
vue2
.0之
axios
使
用
详解_
vue2
axios
引入
直接
用
吗...
[javascript] view plain copy方法一:
直接
在.vue文件中
引入
使
用
在.vue文件中
使
用
i...
赞
踩
article
vue
2.0
---
vue
基础
(
vue
基础
与
axios
)_
vue
双键...
vue
2.0
---
vue
基础
(
vue
基础
与
axios
)_
vue
双键
vue
双键 ...
赞
踩
article
vue2
.0-
axios
_
vue2
调取引
axios
...
axios
简单了解
_
vue2
调取引
axios
vue2
调取引
axios
axios
简介 ...
赞
踩
article
axios
post
请求
参数传输表单数据,其中一个
key
的
value
需要
json
格式, (
qs
的
使用
...
文章讲述了在处理POST
请求
时,遇到content-type为application/x-www-form-urlenc...
赞
踩
article
js中的
ajax
【
Axios
,
XMLHttpRequest
,
Promise
,
async
】回调函数地狱...
js中的
ajax
【
Axios
,
XMLHttpRequest
,
Promise
,
async
】回调函数地狱等问题_js axi...
赞
踩
相关标签
javascript
前端
vue.js
开发语言
ajax
vue2.0
axios
前端技术
http请求
vue
vue-axios
跨域请求
axios深入浅出
elementui
java
后端