新建文本文档 (2)

put请求传递参数的方式

今天项目中提交用户信息修改的时候调用了接口传递了接口但是接口返回错误信息,因为put的话,它的传参方式需要将参数设置为字符串的形式来进行传递,自己上网查了一下才解决

使用put和delete请求,直接指定 ajax 请求中的 type 为 put/delete(不带 _method 参数),并且需要传递参数的时候data需要设置为json字符串

var jsonstr = {"id":1,"name":"zsw"};
$.ajax({
    url:"/update",
    type:"PUT",
    contentType:"application/json",//设置请求参数类型为json字符串
    data:JSON.stringify(jsonstr),//将json对象转换成json字符串发送
    dataType:"json",
    success:function(result){
        alert(result);
    },
});

https://www.cnblogs.com/wwct/p/12396799.html

vant 选择器内容的自定义

还是今天的表单提交修改的项目用到了选择地区地址的功能,所以自己就是上vant找了下,发现给的接口自己不会配合选择器使用,于是自己找到了vant另一个组件Area省市区选择

<van-area title="标题" :area-list="areaList" />

这里要注意areaList,他是官方的一个接口

https://github.com/youzan/vant/edit/dev/src/area/demo/area.js

/asstes/json/area.js
//连接地址边的js文件
import province_list from "../asstes/json/area"
 this.areaList = province_list;

接着配合弹出层就可以写出地址选择的效果

它的默认val为 地区名字和地区号

配合文档进行请求接口就可以了

接着就是选择器内容自定义了

Picker

<van-picker
  title="标题"
  show-toolbar
  :columns="columns"
  @confirm="onConfirm"
  @cancel="onCancel"
  @change="onChange"
/>

上面的columns注意了~~这里要的是一个数组,数组呢里面只能是[“第一个”,“第二个”…]的形式,但是我们要传递的是一个数字,数组内容又只能是文字显示 所以我就是先把当前点击的值进行保存,低级确定的时候,发送获取请求,遍历请求返回的东西,找到与刚才自己保存的文字匹配的一项,保存数字就很ok

subclass(val) {
      console.log(val);
      this.$refs.class.innerHTML = val;
      let token = JSON.parse(localStorage.token);
      attribute({ token }).then(res => {
        console.log(res);
        res.data.data[0].value.map(res => {
          if (res.name == val) {
            this.selectclass = res.id;
          }
        });
        console.log(this.selectclass);
        this.classshow = false;
      });
    },
地区码area.js大全 代码示例: var dsy = new Dsy(); dsy.add("0",["北京市","天津市","上海市","重庆市","河北省","山西省","内蒙古","辽宁省","吉林省","黑龙江省","江苏省","浙江省","安徽省","福建省","江西省","山东省","河南省","湖北省","湖南省","广东省","广西","海南省","四川省","贵州省","云南省","西藏","陕西省","甘肃省","青海省","宁夏","新疆","香港","澳门","台湾省"]); dsy.add("0_0_0",["东城区","西城区","崇文区","宣武区","朝阳区","丰台区","石景山区","海淀区","门头沟区","房山区","通州区","顺义区","昌平区","大兴区","怀柔区","平谷区","密云县","延庆县","延庆镇"]); dsy.add("0_0",["北京市"]); dsy.add("0_1_0",["和平区","河东区","河西区","南开区","河北区","红桥区","塘沽区","汉沽区","大港区","东丽区","西青区","津南区","北辰区","武清区","宝坻区","蓟县","宁河县","芦台镇","静海县","静海镇"]); dsy.add("0_1",["天津市"]); dsy.add("0_2_0",["黄浦区","卢湾区","徐汇区","长宁区","静安区","普陀区","闸北区","虹口区","杨浦区","闵行区","宝山区","嘉定区","浦东新区","金山区","松江区","青浦区","南汇区","奉贤区","崇明县","城桥镇"]); dsy.add("0_2",["上海市"]); dsy.add("0_3_0",["渝中区","大渡口区","江北区","沙坪坝区","九龙坡区","南岸区","北碚区","万盛区","双桥区","渝北区","巴南区","万州区","涪陵区","黔江区","长寿区","合川市","永川区市","江津市","南川市","綦江县","潼南县","铜梁县","大足县","荣昌县","璧山县","垫江县","武隆县","丰都县","城口县","梁平县","开县","巫溪县","巫山县","奉节县","云阳县","忠县","石柱土家族自治县","彭水苗族土家族自治县","酉阳土家族苗族自治县","秀山土家族苗族自治县"]); dsy.add("0_3",["重庆市"]); ...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值