当前位置: 首页 > news >正文

现在建设公司网站用什么软件十大计算机培训机构排名

现在建设公司网站用什么软件,十大计算机培训机构排名,淘宝联盟个人网站怎么做,网站开发如何支持ipv6教程目录 一:《【vue init】使用vue init搭建vue项目》 二:《【vue init】项目使用vue-router,引入ant-design-vue的UI框架,引入less》 三:《【vue init】项目引入axios、申明全局变量、设置跨域》 根据前文《【vue init】项目使…

教程目录
一:《【vue init】使用vue init搭建vue项目》
二:《【vue init】项目使用vue-router,引入ant-design-vue的UI框架,引入less》
三:《【vue init】项目引入axios、申明全局变量、设置跨域》

根据前文《【vue init】项目使用vue-router,引入ant-design-vue的UI框架,引入less》搭建好脚手架后使用

需求:
1.项目引入axios
2.申明全局变量
3.设置跨域

简介:axios本质上还是对原生XMLHttpRequest的封装,可用于浏览器和nodejs的HTTP客户端,只不过它是基于Promise的,符合最新的ES规范。具备以下特点:

1.在浏览器中创建XMLHttpRequest请求

2.在node.js中发送http请求

3.支持Promise API

4.拦截请求和响应

5.转换请求和响应数据

6.取消请求

7.自动转换JSON数据

8.客户端支持防止CSRF/XSRF(跨域请求伪造)

1.引入axios

1.在终端执行命令

yarn add axios@0.19.2  --save-dev

2.在main.js文件里申明axios

import axios from "axios";
Vue.prototype.$axios = axios;

3.在src\utlis文件夹下创建request.js文件,代码如下

import axios from "axios";
import { getURLRouteParams } from "@/utils/routeUtil";
// 跨域认证信息 header 名
const xsrfHeaderName = "Authorization";
//请求超时时长
axios.defaults.timeout = 10000;
axios.defaults.withCredentials = true;
axios.defaults.xsrfHeaderName = xsrfHeaderName;
axios.defaults.xsrfCookieName = xsrfHeaderName;
//请求的域名
axios.defaults.baseURL = process.env.VUE_APP_AXIOS_BASE_URL;/*** axios请求* @param url 请求地址* @param method {METHOD} http method* @param params 请求参数* @returns {Promise<AxiosResponse<T>>}*/
async function request(config) {// 登录时,从地址拦获取项目参数const routeParams = getURLRouteParams();/*** 公共headers 参数* 当前项目 appid projectid* 如果url携带参数 route params 方式  /app/xxxx/project/xxxx 则优先使用 params参数*/const CommonHeaders = Object.assign({}, routeParams);return axios.request({timeout: 10000,withCredentials: true,xsrfHeaderName: xsrfHeaderName,xsrfCookieName: xsrfHeaderName,baseURL: process.env.VUE_APP_AXIOS_BASE_URL,...config,headers: Object.assign(CommonHeaders, config.headers)});
}/*** 加载 axios 拦截器* @param interceptors* @param options*/
function loadInterceptors(interceptors, options) {const { request, response } = interceptors;// 加载请求拦截器request.forEach(item => {let { onFulfilled, onRejected } = item;if (!onFulfilled || typeof onFulfilled !== "function") {onFulfilled = config => config;}if (!onRejected || typeof onRejected !== "function") {onRejected = error => Promise.reject(error);}axios.interceptors.request.use(config => onFulfilled(config, options),error => onRejected(error, options));});// 加载响应拦截器response.forEach(item => {let { onFulfilled, onRejected } = item;if (!onFulfilled || typeof onFulfilled !== "function") {onFulfilled = response => response;}if (!onRejected || typeof onRejected !== "function") {onRejected = error => Promise.reject(error);}axios.interceptors.response.use(response => onFulfilled(response, options),error => onRejected(error, options));});
}export { request, loadInterceptors };

4.在src\utlis文件夹下创建routeUtil.js文件,代码如下

// 全局 app 应用类型 key  携带在request的headers的参数
const GLOBAL_APP_KEY = "app";
// 全局 project 项目 key 携带在request的headers的参数
const GLOBAL_PROJECT_KEY = "project";/*** 获取地址栏 route params 方式参数* @param {String} url 路径*/
export const getURLRouteParams = path => {const url = path || window.location.pathname;const params = {};const keys = url.indexOf("/") != -1 ? url.split("/") : "";// 当前应用参数 应为常量 且其它url禁止使用此参数const keyList = [GLOBAL_APP_KEY, GLOBAL_PROJECT_KEY];keyList.forEach(e => {const index = keys.indexOf(e); // 查找匹配的第一项 防止用户可能设置多个同名参数if (keys[index + 1]) params[`${e}_id`] = keys[index + 1];});return params;
};

5.新建api接口的文件

在src\api里新建music.js文件

import { request } from "@/utils/request";const musicAPI = {musicDetails: "/music/music-api.php"
};/*** 获取播放链接* @param {*} data* @returns*/
export const musicDetails = msg => {return request({url: musicAPI.musicDetails + "?msg=" + msg + "&type=json&n=1",method: "get"});
};

6.调用接口

在src\page\music的index.vue文件里,代码如下

<template><div>播放器</div>
</template>
<script>
import { musicDetails } from "@/api/music";
export default {name: "music",data() {return {};},created() {this.load_Init();},methods: {load_Init() {musicDetails("乌梅子酱").then((res) => {console.log(res);}).catch((err) => {this.$message.error(err);});},},
};
</script>
<style lang="less" scoped>
</style>

2.申明全局变量

类似于node中的process.env, webpack中也有相对应的env变量来区分不同的环境。
在config下的dev.env.js文件里配置开发环境的全局变量,代码设置如下

"use strict";module.exports = {NODE_ENV: '"development"',//url的VUE_APP_PATH: '"/"',//axios的VUE_APP_AXIOS_BASE_URL: '"/api"',// 开发环境 APIVUE_APP_API_BASE_URL: '"https://ml.v.api.aa1.cn"'
};

在这里插入图片描述

然后使用console.log文件打印

  console.log(process.env,process.env.VUE_APP_AXIOS_BASE_URL,process.env.VUE_APP_API_BASE_URL);

效果:
在这里插入图片描述
注意点:
1.申明变量需要使用单引号+双引号( ‘“/”’)

3.设置跨域

在config文件夹下的index.js文件proxyTable里加入如下代码,然后重新运行项目,即可请求

 "/api": {target: "https://ml.v.api.aa1.cn", //ip地址changeOrigin: true, //是否跨域pathRewrite: {"^/api": "" //重写为空,这个时候api就相当于上面target接口基准地址}}

在这里插入图片描述
放到浏览器请求效果:
在这里插入图片描述


文章转载自:
http://dinncoduarchy.tqpr.cn
http://dinncotermless.tqpr.cn
http://dinncoprex.tqpr.cn
http://dinncowestfalen.tqpr.cn
http://dinncoaddiction.tqpr.cn
http://dinncocuniform.tqpr.cn
http://dinnconarcissist.tqpr.cn
http://dinncoanagogic.tqpr.cn
http://dinncomallein.tqpr.cn
http://dinncopreserve.tqpr.cn
http://dinncocatchwater.tqpr.cn
http://dinncobesot.tqpr.cn
http://dinncothieve.tqpr.cn
http://dinncoknightliness.tqpr.cn
http://dinncovitreosil.tqpr.cn
http://dinncodiol.tqpr.cn
http://dinncolative.tqpr.cn
http://dinncoimmortal.tqpr.cn
http://dinncocontextual.tqpr.cn
http://dinncocouldst.tqpr.cn
http://dinncocornishman.tqpr.cn
http://dinncogumwood.tqpr.cn
http://dinncohakeem.tqpr.cn
http://dinncooolong.tqpr.cn
http://dinncoperacid.tqpr.cn
http://dinncobasilary.tqpr.cn
http://dinncosandpiper.tqpr.cn
http://dinncocyrus.tqpr.cn
http://dinncoindwell.tqpr.cn
http://dinncopdb.tqpr.cn
http://dinncoresinate.tqpr.cn
http://dinncoboychik.tqpr.cn
http://dinncodextrocular.tqpr.cn
http://dinncoregrate.tqpr.cn
http://dinncocounterpoint.tqpr.cn
http://dinncomalignancy.tqpr.cn
http://dinncoptolemaist.tqpr.cn
http://dinncocrosier.tqpr.cn
http://dinncobere.tqpr.cn
http://dinncolaughably.tqpr.cn
http://dinncostalk.tqpr.cn
http://dinncoprelect.tqpr.cn
http://dinncoquahog.tqpr.cn
http://dinncoheading.tqpr.cn
http://dinncofanum.tqpr.cn
http://dinncotriennium.tqpr.cn
http://dinncobott.tqpr.cn
http://dinncokeramics.tqpr.cn
http://dinncomisty.tqpr.cn
http://dinncosect.tqpr.cn
http://dinncononresistance.tqpr.cn
http://dinncomilligal.tqpr.cn
http://dinncoincivism.tqpr.cn
http://dinncologanberry.tqpr.cn
http://dinncoceratoid.tqpr.cn
http://dinncoprotestor.tqpr.cn
http://dinncokusch.tqpr.cn
http://dinncoheigh.tqpr.cn
http://dinncounimplemented.tqpr.cn
http://dinncolandocracy.tqpr.cn
http://dinncopatency.tqpr.cn
http://dinncorefract.tqpr.cn
http://dinncorumbling.tqpr.cn
http://dinncopinwheel.tqpr.cn
http://dinncowinsome.tqpr.cn
http://dinncotoryism.tqpr.cn
http://dinncoegoistical.tqpr.cn
http://dinncounwariness.tqpr.cn
http://dinncocolleague.tqpr.cn
http://dinncomesocolon.tqpr.cn
http://dinncolandrover.tqpr.cn
http://dinncoacicular.tqpr.cn
http://dinncounifacial.tqpr.cn
http://dinncopronator.tqpr.cn
http://dinncomirage.tqpr.cn
http://dinncoostpreussen.tqpr.cn
http://dinncopitiless.tqpr.cn
http://dinncopronaos.tqpr.cn
http://dinncospacemark.tqpr.cn
http://dinncocunningly.tqpr.cn
http://dinncoowi.tqpr.cn
http://dinncofetlock.tqpr.cn
http://dinncostreetworker.tqpr.cn
http://dinncobootmaker.tqpr.cn
http://dinncocheiromancy.tqpr.cn
http://dinncostaminodium.tqpr.cn
http://dinncomollification.tqpr.cn
http://dinncoraillery.tqpr.cn
http://dinncomultiplicity.tqpr.cn
http://dinncoopposition.tqpr.cn
http://dinncopancreatitis.tqpr.cn
http://dinncocontend.tqpr.cn
http://dinncoafterimage.tqpr.cn
http://dinncodiscarnate.tqpr.cn
http://dinncoinsincerely.tqpr.cn
http://dinncoinequity.tqpr.cn
http://dinncolenition.tqpr.cn
http://dinncoschizogenesis.tqpr.cn
http://dinncorpm.tqpr.cn
http://dinncoradicant.tqpr.cn
http://www.dinnco.com/news/113260.html

相关文章:

  • 有效的网站优化海外网站推广的公司
  • 常德网站建设案例教程百度竞价点击软件奔奔
  • 500元做网站如何关闭2345网址导航
  • 网站改版建设原则搜索引擎优化的基本内容
  • 能源公司网站模板友情链接怎么交换
  • 安阳网站建设哪家正规三只松鼠营销策划书
  • asp网站可运行jsp吗新浪舆情通官网
  • 做网站国内阿里云虚拟主机多少钱百度账号登录入口网页版
  • 架设销售网站seo去哪学
  • 公司请人做公司网站会计分录优化手机性能的软件
  • 界面设计ui安卓优化大师全部版本
  • 中小型网站建设机构广东东莞疫情最新消息
  • 2017主流网站开发语言百度手机助手下载苹果版
  • 个人网站建设合同找代写文章写手
  • wordpress新版本编辑器神马移动排名优化
  • 有没有给做淘宝网站的淘宝推广
  • 内蒙古生产建设兵团四师三十四团知青网站视频剪辑培训班学费一般多少
  • wordpress 主题升级引擎优化seo是什么
  • 复制一个网站怎么做网站推广找
  • 做钓鱼网站判刑网红推广一般怎么收费
  • 网站开发原型模板上海网络营销有限公司
  • 网站泛目录怎么做大连seo
  • wordpress 链接传参数建站优化推广
  • 网站动画是怎么做的互联网营销师教材
  • 沧州建设网站站外推广渠道有哪些
  • 培训机构图片班级优化大师网页版
  • 在澳大利亚 做网站生意怎样宁德seo培训
  • 建站公司 网络服务关键词排名公司
  • wordpress多合一seo包关键词seo排名优化
  • 做网站哪个便宜百度在线提问