博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vue2.0 仿手机新闻站(四)axios
阅读量:7065 次
发布时间:2019-06-28

本文共 1399 字,大约阅读时间需要 4 分钟。

1.axios的配置

main.js

import Vue from 'vue'import App from './App.vue'// 引入 路由import VueRouter from 'vue-router'// 引入 路由配置文件import routes from './router.config'// 引入 vuex入口文件import store from './store/index'// 引入 axiosimport axios from 'axios'// 引入 loading 组件import Loading from './components/loading'Vue.use(VueRouter);Vue.use(Loading);// 关于axios配置axios.interceptors.request.use(function(config){	// 发送请求	store.dispatch('showLoading');	return config;},function(error){	return Promise.reject(error);});axios.interceptors.response.use(function(response){	// 请求回来	store.dispatch('hideLoading');	return response;},function(error){	return Promise.reject(error);});// 配置请求的根路径// axios.default.baseURL = 'http://localhost:8080';// 设置默认头部信息 post// axios.default.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';// 把axios对象挂到Vue原型上Vue.prototype.$http = axios;// 创建 路由const router = new VueRouter({	mode:'history', // 删除 url 中的'#'号,切换路径模式	scrollBehavior:() => ({y:0}), // 滚动条滚动的行为,不加这个默认就会记忆原来滚动条的位置	routes // routes 等价于 routes:routes});require('./assets/css/base.css'); // 全局引入new Vue({  	el: '#app',  	router,  	store,  	render: h => h(App)})

 

2. 组件中的使用

Home.vue

 

3.静态数据

 

4.效果图

转载于:https://www.cnblogs.com/crazycode2/p/7580398.html

你可能感兴趣的文章
使用Windows8开发Metro风格应用七
查看>>
(第一天)包装对象、作用域、创建对象
查看>>
POJ 3104:Drying(二分)
查看>>
Stardew Valley(星露谷物语)Mod开发之路 1环境配置
查看>>
2012 借教室
查看>>
为什么是Spring Boot
查看>>
前端之本http协议
查看>>
python基础-协程
查看>>
JavaScript数据类型
查看>>
zoj 1004 Anagrams by Stack (dfs+stack)
查看>>
iOS NSDecimalNumber 使用
查看>>
hdu 2844 混合背包【背包dp】
查看>>
函数分析题
查看>>
debian手册摘要
查看>>
TreeMap 原理
查看>>
iOS开发工具——网络封包分析工具Charles
查看>>
iis7负载均衡
查看>>
【iOS开发-47】怎样下载iOS 7.1 Simulator 以及iOS 8离线的Documentation这些文件?
查看>>
多种方式求阶乘
查看>>
页面中引入mui 地址选择,点击页面中其他input时页面回到顶部
查看>>