axios的get请求 - 代码篇

版权声明:本文为博主原创文章,允许转载,但转载必须注明出处并附带首发链接 https://blog.csdn.net/qq_35393869/article/details/88600722

vue + elemetUI + axios的get方式请求(踩坑篇)

bug代码示例:

一、<script> · 部分代码
data() {
      return {
				resumes :[],
				xss: [],
				dialogShareFormVisible: false, // 弹框:新建分享 默认不显示
      }
},

// ================================================================================
// 异步请求:获取选项字典
ajaxOptionsOfShareForm: function (e,dialogShareFormVisible,xss){
	this.dialogShareFormVisible = true;
	var key = localStorage.getItem("token");
	console.log("获取选项字典"+key)

	var localPath = this.GLOBAL.localSrc;  // 本地 接口地址
    var serverPath = this.GLOBAL.serverSrc; // 线上 接口地址

	axios.get( serverPath + '/state',
		{
			params:{  // 注意1:
			
			},
			headers: { // 注意2:
				'Content-Type':'application/json',
				'Authorization': key
			}
		}
	)
	.then(function (response) {
		if (response.data.code == "200"){
			// 弹框成功提示
			this.$notify({
				title: response.data.message,
				type: 'success',
				duration: 2000
			});
		}

		localStorage.setItem("token",response.headers.authorization); // token 复写本地 localStorage					

		console.log("选项字典"+response.data.data.jobIndustry);

		this.xss = response.data.data.jobIndustry
	

	}.bind(this))
	.catch(function (error) {
			console.log("请求失败"+error);
	});

二、<templete> · 部分代码
<el-form-item label="意向职业" :label-width="labelWidth">
	<!-- <el-input v-model="form.jobIntention"  placeholder="例如:电话销售,网络销售,房产销售等" autocomplete="off"></el-input> -->
	<el-select v-model="form.jobIntention" placeholder="例如:电话销售,网络销售,房产销售等">
		<el-option v-for="(xs,index) in xss" :key="index" :label="xs.dictLabel" :value="xs.dictValue"></el-option>
	</el-select>
</el-form-item>

三、postman截图 · 部分API代码

在这里插入图片描述


相关阅读思考:

实际测试发现,这个方法是不行的。


具体参考项目get请求页面···

  1. searchMain.vue文件
	// 条件查询: 异步请求:获取选项字典
	axios.get( serverPath + '/state',
		{
			params:{

			},
			headers: {
				'Content-Type':'application/json',
				'Authorization': key
			}
		}
	)
	.then(function (response) {
		localStorage.setItem("token",response.headers.authorization); // token 复写本地 localStorage					

		console.log("选项字典"+response.data.data.jobIndustry);

		this.qzzts = response.data.data.jobWantedState // 求职状态
		this.xls = response.data.data.jobEducation // 学历

	}.bind(this))
	.catch(function (error) {
			console.log("请求失败"+error);
	});

  1. .XML文件(待补充)



以上就是关于“ axios的get请求 - 代码篇 ” 的全部内容。

猜你喜欢

转载自blog.csdn.net/qq_35393869/article/details/88600722
今日推荐