vue+axios安装
Axios是一个基于promise的HTTP库,可以用在浏览器和node.js中。
安装方式:
1.使用cdn
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
2.使用npm安装
npm/cnpm install axios
在main.js中import axios并将其挂载到Vue实例上
import Axios from 'axios'
Vue.prototype.$axios = Axios //调用时使用this. $axios()
3.点击随机切换笑话的小例子
<template>
<div id="app">
<input type="button" name id value="获取笑话" @click="getJoke" />
<p>{{joke}}</p>
</div>
</template> <script>
export default {
name: "App",
data: () => {
return {
joke: "很好笑的笑话"
};
},
methods: {
getJoke: function() {
// axios回调函数中的this已经改变,无法访问到data中数据
// 可以var that = this; 回调函数中用that访问data中数据
var that=this;
this.$axios({
url: "https://autumnfish.cn/api/joke",
methods: "get"
}).then(
function(response) {
console.log(response.data);
that.joke=response.data
},
function(err) {}
);
}
},
created: function() {}
};
</script> <style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
} ul,
li {
list-style: none;
}
</style>
vue+axios安装的更多相关文章
- vue axios数据请求get、post方法的使用
我们常用的有get方法以及post方法,下面简单的介绍一下这两种请求方法 vue中使用axios方法我们先安装axios这个方法 npm install --save axios 安装之后采用按需引入 ...
- VUE的安装与Django之间打通数据
一 VUE的安装与项目创建 1.1.安装nodeJS 官网下载安装:https://nodejs.org/zh-cn/ 1.2.安装脚手架 vue官网 => 学习 => 教程 => ...
- vue axios 应用
vue安装axios cnpm install axios 安装成功后/项目/node_modules/目录下有axios文件夹 在package.json文件中devDependencies字段中添 ...
- vue axios 总结篇
1.npm --save 和 --save-dev 有什么区别 发布到线上的叫生产环境~,在本地开发的时候叫开发环境,--save就是会打包到线上去并且在线上环境能用到的,比如你npm install ...
- vue的安装配置与项目创建
1,安装vue必须先安装node.js. --------去官网安装node.js 因为npm依赖node.js环境,使用npm的时候需要安装node.js.安装node.js的时候npm会默认安装 ...
- 10.2 Vue 环境安装
Vue 环境安装 环境准备 nodejs 下载安装 https://nodejs.org/en/ 查看下载版本 C:\>node -v v7.6.0 C:\>npm -v 4.1.2 ...
- vue axios 取消上次请求
axios.defaults.timeout = 1000 * 5axios.defaults.baseURL = baseUrlvar CancelToken = axios.CancelToken ...
- VUE项目安装
连接转载:https://www.cnblogs.com/Colwill-Blog/p/6682091.html 刚刚开始学习Vue.js.今天分享一下我的Vue项目安装过程. 我是windows系统 ...
- vue axios拦截器 + 自编写插件 实现全局 loading 效果;
项目需求:用自定义的 .gif 图标实现全局 loading 效果:为避免在每个页面手动添加,且简单高效的实现,经查阅资料,最终采用了 vue axios拦截器 + 自编写 loading 插件:下面 ...
随机推荐
- PP: Tripoles: A new class of relationships in time series data
Problem: ?? mining relationships in time series data; A new class of relationships in time series da ...
- localStorage存、取数组
localStorage存储数组时需要先使用JSON.stringify()转成字符串,取的时候再字符串转数组JSON.parse(). var arr=[1,2,3,4]; localStorage ...
- 解决:java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject报错问题。
利用POI操作PPT一直报如下错误java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject 是因为项目中缺少一个包xmlbeans ...
- android获取系统信息
连接手机,adb shell 进入 Android Shell 模式,输入 getprop 获取系统属性值 通过上面方法拿到属性名,然后通过下面方法获取到系统的属性值 /** * 获取build.pr ...
- 三、linux环境的搭建1(oracle、ssh、jdk、mysql、samba、tomcat)
linux环境的搭建1(oracle.ssh.jdk.mysql.samba.tomcat) 网络配置 方案一 tip 1 使用ifconfig : ifconfig eth0 新ip 然后编辑/ ...
- Git分支基本命令+coding webhook+lnmp
首先介绍一写基本的git操作命令: 查看当前项目的远程地址: git remote -v 查看远程地址所有分支: git branch -a 或者 git branch -r 查看本地分支与远程分支的 ...
- Centos7 入门几个操作
http://www.wallcopper.com/linux/1650.html 创建文件软连接 ln -s 源路径 目标路径 查看软连接ls -il 服务操作:systemctl start fo ...
- soundtouch change pitch matlab implementation
function output = changePitch(input, pitchInSemitones) % one octave is 12 semitones octave = pitchIn ...
- centos7 walle2瓦力部署教程
项目部署上线,如果是单服务器,那么有多种方式可以部署,比如直接ftp上传,或者直接git去拉取,人工操作也不会花费精力和时间,但是如果采用了集群模式,有多台服务器,那么依靠一台一台的去上传代码,就显得 ...
- MongoDB - String转换为Int,并更新到数据库中
方法1 使用$convert, MongoDB版本 >= 4,速度快. 使用pymongo示范,原生mongo语句并没有尝试. # 假设{'age': '47'}, 转换后为{'age': 47 ...