vue安装axios

cnpm install axios
安装成功后/项目/node_modules/目录下有axios文件夹
在package.json文件中devDependencies字段中添加插件名和插件版本
"axios": "^0.17.1", 在vue项目中引用axios
1.src/main.js
import axios from 'axios'
Vue.prototype.$axios = axios show: function(){
//get方式 //赋值给变量self
var self = this; var url = "hotcity.json";
axios.get(url,{
params:{
username: "egon"
}
})
.then(function (response) {
self.stu = response.data.data.hotCity;
console.log(response.data.data.hotCity);
})
.catch(function (error) {
console.log(error);
}) } show: function(){
//post方式
//var url = "http://bugwhy.com/php/index/getNews.php";
var url = "http://localhost:8000/login";
axios.post(url,{
name: this.username,
password: this.password
},{
"headers": {"Content-Type": "application/x-www-form-urlencodeed"}
}).then(function(res){
console.log(res.data);
})
.catch(function (error) {
console.log(error);
}) }

  

最新文章

  1. Python运算符,python入门到精通[五]
  2. UVA11987Almost Union-Find(并查集删除节点)
  3. IO基础
  4. MST:Out of Hay(POJ 2395)
  5. 118. 119. Pascal's Triangle -- 杨辉三角形
  6. DevExpress GridControl GridView 导出到 Excel 类
  7. EL表达式(转)
  8. 图数据库 Titan 高速入门
  9. Spring 基于Java的Bean声明
  10. SQL Server 安装报错找不到vc_red.msi
  11. wpf XAML xaml 进行 数据绑定,Resource DataContext ElementName
  12. Gradle 1.12用户指南翻译——第三十八章. Eclipse 插件
  13. oracle如何创建存储过程和调用
  14. codeblocks: 使用动态链接库(pcre)的配置
  15. Spring+Hibernate 多数据源不同事务创建
  16. mysql导出长数字到excel避免显示为科学记数法 解决方法
  17. python 守护进程,监控进程
  18. 字符串和数组----string
  19. MySQL1安装
  20. Laravel 的 JSON API 接口自动化测试

热门文章

  1. linux基础(1)-yum源配置
  2. java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\x88\xE6\x88...' for column 'content' at row 1
  3. QT XML文档的解析 QXmlStreamReader, DOM,SAX 三种解析方法 简单示例
  4. redis 按空间范围查询点位
  5. android EventBus的简单使用
  6. servlet cannot be resolved to a type解决办法
  7. .NET和Docker ,比翼双飞
  8. PHP用mysql_insert_id()函数获得刚插入数据或当前发布文章的ID
  9. hdu-2544-最短路(SPFA模板)
  10. 一段tcl代码